Suggestions and observations around server.sleepfor()

My imp is typically woken up on demand (by button interrupt), and otherwise sleeping. To be a nice citizen, I want to wake up every 24 hours (e.g. to get firmware updates) but no more. So naturally I used


I’ve found that this does not work. Later I found it mentioned on the forum that 24 hours is the max. Here are the potential issues around the behavior that I did see:

  1. I had to go a few seconds under 24 hours for it to work. Just a few seconds, but still it was confusing.
  2. If I used the number above (86400), the device would reboot every 6 seconds, with no errors or warnings. It would be good to give an error when a too-high number is used.
  3. The 24 hour limit should probably be added to the API docs as well.
  4. Minor, but the amount of time to sleep is in seconds, but the log when you sleep prints out milliseconds (always with three zeros for the ms). E.g. “sleeping until 1361260930000”. This was confusing when I was trying to debug, as I would print out time() right before sleeping, and I expected it to be comparable to the sleep log entry.

Code that reproduces the issues:

server.log("Starting execution"); imp.wakeup(5, function() { server.log(format("Sleeping at %d", time())); //server.sleepfor(86390.0); // This value works fine server.sleepfor(86400.0); // This value causes a reboot 6 seconds after boot });

Hope this helps others and can eventually get updated in the docs and code.