Deep sleep during specific times

For the purpose of saving battery power, I’d like my photon to sleep between 3pm and 9am, awake from 9am to 3pm. Could I just run a loop which checks the current time, say every 60 seconds, and if the time falls within the “sleep” time, run the sleep method -and if the time falls within the “awake” time, wake it up? This would use no interrupts, just software timing. Thanks!

You can’t be checking the time while the device is asleep, so you would have to wake it up every 60 seconds to do what you propose. However, there’s no need to do that. Just check the time at some interval while the device is awake, and when it’s 3 PM tell the system to go to sleep until 9 the next morning. Look at mdma’s last post in this [thread][1] to see how to do that. Or, you could simply pass the number of seconds between 3 PM and the following 9 AM, which is 64,800.

if (Time.hour() == 15 && Time.minute() == 0) {
    Sytem.sleep(SLEEP_MODE_DEEP, 64800);
}

Be sure to set your time zone (in setup), with Time.zone().
[1]: Have System.sleep SLEEP_MODE_DEEP wakeup at the same time everday

3 Likes