Have System.sleep SLEEP_MODE_DEEP wakeup at the same time everday

The “UNIX epoch time” used here is a count of seconds since midnight 1/1/1970 (with no account for leap seconds).

There are some C functions (like localtime and its relatives) you could use, or you do the relative maths with the functions you get with the Time library (e.g. (Time.now()) - (Time.now() % 86400) + (86400) + (14*3600) = “current second” - “seconds since midnight” + “seconds of one day” + “seconds of fourteen hours”)

If you want to wake at a given time (hh:mm:ss) on the following day, you would do something like this

  //               (      till midnight       ) and (   another x seconds    ) 
  int secs2sleep = (86400 - Time.now() % 86400)  +  (hh * 3600 + mm * 60 + ss); 
  System.sleep(SLEEP_MODE_DEEP, secs2sleep);
3 Likes