settimeout - how long is too long?

Posted on
  • I am experiencing some instability that might be attributable to calling a settimeout for over 14 hours. Is there a maximum recommended settimeout length?

  • There shouldn't be... You can check by looking at Espruino's internals:

    >setTimeout(function() {
    :}, 1000*3600*15 /* 15 hours */);
    =1
    =[ undefined,
      { "time": 56599003766,
        "callback": function () {}
       }
     ]
    

    time is the timeout in internal time units (1024*1024=1048576 on the STM32 Espruino boards), and you should be able to see if it's set to what you expect. It appears to work fine on mine.

    Which board are you using? And are you using setDeepSleep?

    An unlikely problem might be that there is some issue with the lower levels, which don't manage to wake it up at the correct time for long time periods.

    To get around that, just try adding a setInterval(function(){}, 1000*3600) - it'll make sure the board wakes up every hour regardless of whatever else it's doing. If that fixes the problem we'll know that it is something to do with the lower levels - but it seems unlikely.

  • Thank you. Esp8266 is the board I am using (esp12). I will add in that 1 hour timer and see if it helps.

    I am not using a deep sleep as I have a webserver going as well.

  • I don't think ESP8266 does deep sleep in the same way anyway - I guess it could potentially have an overflow problem for long time periods... Let us know how it goes with the 1 hour timer!

  • @Gordon - I am indeed finding that the

    setInterval(function(){}, 1000*3600)
    

    is useful in my application to keep the ESP from turning into a zombie. I have spent some efforts troubleshooting a variety of other possible problems, so cannot say for sure it is not an issue with capacitor, the chip I was using, or other bug in the code, but the version of the code I have running currently, with the setinterval on top of it, is working fine.

    The code (currently without setInterval checked in) can be found here, if you are curious.

    https://github.com/wga22/esp8266/blob/ma­ster/espurino/landscape_AP.js

  • Thanks for letting me know.

    Actually just had a quick look at it and I can't see anything obvious (the ESP8266 port doesn't do any fancy timing - it just runs Espruino as fast as it can). Maybe if you have the problem again, take a look at the debugging command posted above and see if anything looks wrong.

    It's possible that the time from getTime() overflows every so often?

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

settimeout - how long is too long?

Posted by Avatar for Will @Will

Actions