Timers and wifi outage

In device code, a timer was started for example for 1800 seconds. Simultaneously, a wifi outage occurred and device rebooted after 900 seconds. Now, the timer is also lost. How can we make timers survive such reboots?


You can’t make a timer survive a reboot directly. What you can do is save the timer details (duration and callback) in the nv table and, on reboot, check for any timer records in nv and restore them with fresh imp.wakeup() calls. When a timer fires, you have to remove it from nv, of course.

This is some management hassle, so it’s probably best to set your device so that its imp doesn’t sleep when WiFi is lost. Changes its disconnection policy to RETURN_ON_ERROR using server.setsendtimeoutpolicy().

Further info in ‘Running an imp Offline’