setTime and setInterval

Posted on
  • Hi Gordon

    I still have some problems with my pico farm, connected over an xbee mesh.
    Problem: setInterval is not called anymore.

    I first had the impression that it was the psu. That's not the case.
    I broadcast the time every 5 minutes from my Linux server over xbee and set the time on the picos using setTime();

    In fact, my setInterval is called often before the first setTime() was executed.

    I commented the setTime() function out on my test pico. The problem is gone.
    I tried to isolate it to reproduce the problem. At the moment i was not able to reproduce a stop of calling the setInterval function. But this code shows that setInterval and maybe setTimeout is not setTime proof/aware.

    Try this code: It should be called every 30 Seconds

    console.log('Hello Espruinos');
    console.log(getTime());
    console.log('Setting up setInterval');
    setInterval(function() { console.log('Called:'+getTime()); }, 30000);

    setTime(467835036);

    The setInterval function is called rapidly as fast as possible.

    I need a way to use setInterval in parallel of using setTime. A work around could be to clear the intervals before calling setTime and start it again. But this is not so handy. Because my code is very object oriented. It not easy to handle that. Is there another work around ?

    Thanks for your help.

    Sacha

    Greatings

    Sacha

  • I'm feeling like a ghost hunter! After an hour or so, my setInterval is not called anymore. Also when I don't use setTime. The theory about setTime() could be wrong again.

  • Hmm, not sure what's up...

    Did you see the recent 1v86 release? You could try using E.kickWatchdog() - it's not ideal, but might be good enough?

    Also, if you want to avoid setTime then you could potentially do something like:

    var timeOffs = 0;
    function safeSetTime(t) {
      timeOffs = t-getTime();
    }
    function safeGetTime() {
      return timeOffs + getTime();
    }
    
  • I have the problems also when not using setTime..... E.kickWatchdog is realy not ideal.
    Is there a way to debug, display registered or pending setInterval's / setTimeout's ?

  • I think it's best to discuss that on the original thread: http://forum.espruino.com/conversations/­289312

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

setTime and setInterval

Posted by Avatar for Sacha @Sacha

Actions