I have implemented a feature to do future ON for my device.
because i wanted to take into account extreme cases where it might shut down unexpectedly, i have this mechanism:
- get a command to turn on in 2 hours
- every minute, advance a counter by 1 (till it reaches 120)
- every minute, update server permanent table with values
i also have a counter to avoid multiple wakeups (so that it will be cancellable), so each minute i check that the counter variable is the same as the one I have (the 1 minute callback contains the value i started with)
the thing is, it causes alot of ugly code…and too many variables imo
I could just do imp.wakeup(12060, onfunction) but in case server crashes, thats a problem.
I could also do var = 120, imp.wakeup(12060, onfunction) and every minute do var-- , which is a little easier.
Is there a way to save wakeup callbacks (its like a stack, isnt it?) and just backup/restore to/from server?
All timers maximum value is less than 24 hours, which is a bug i noticed here in forums
This approach is mainly because I wish to be able to cancel those scheduled wakeups, so I use counter to see if its still relevant…because i cant cancel a wakeup