1

So, I've made a Twitter bot using node.js, slightly modified from this guide, which is supposed to send a tweet every two hours (using Javascript's setInterval() function). Running on a Windows 7 laptop, this works fine. It also works fine on my Raspberry Pi 3 when I set it for a short timer, say, a few minutes, but set to two hours it does nothing. No error message or anything, the terminal window just doesn't seem to do anything at all.

My OS is Ubuntu MATE 16.04 (specifically, the version for Raspberry Pi), but I've also tried Raspbian with no success.

Node.js is version 6.9.2, though I initially had version 4.6 or so (IIRC).

At first I thought the problem may be the system going into some kind of power saving mode, but I've tried using Caffeine and even having the Pi ping itself every few seconds, but no success there, either.

I suspect that the problem is that the Pi doesn't have an internal clock and thus can't run the script's setInterval() function accurately. So, since I first posted this question, I have bought an RTC module, and set it up using this guide (technically for Ubuntu MATE 15.10). The clock is working, which is nice, but the script still does not run when set for more than a few minutes.

0

I've found, not a solution, but a workaround for the problem with some help from RaspberryPi.org's forum. Apparently this is a known issue. It's not clear to me what causes the problem, but that link leads to this thread, where the OP got a similar script to work by adding a second setInterval() method, like so:

setInterval(function () {
console.log('20-minute interval trigger! It is now %s', (new Date()));
}, 1000 * 60 * 20);

I added that to my existing script, and now everything works as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.