Running the imp continuously without sleep for extended periods

I have an application for running the imp in an always-on, wall-powered mode. It would need to run on the order of years without being powered off. Are there any special cases that I should take into consideration?

  1. If the wifi disconnects, will it be OK to try reconnecting indefinitely? If the wifi were down for some longer period (eg. 72 hours) would the imp003 hardware overheat or otherwise be damaged trying to reconnect continuously for that long?

  2. Should I force the imp to deep sleep occasionally? Any benefit besides forcing memory recycling?

If it’s always wall-powered, you don’t ever have to make it sleep. It doesn’t get tired, nor does it get hot. A “health watchdog” could be programmed into the device/agent to periodically log an entry into a website database online. A widget on anyone’s website could show a green light if things are OK, otherwise a red light if it determines entries were missed. You could have a graph of any missed entries, indicating drop-outs in your wall power or wifi.

This should be fine. Yes, you can keep attempting to reconnect indefinitely, there’s no thermal issue (reconnects take less current than constant transmission for example). Quite a few of the commercial imp-based products run in this mode.

A deep sleep effectively causes a reboot. If you had issues with memory fragmentation over time, then that would clear the issue but a failed memory allocation will reboot too, so probably not required :slight_smile:

Excellent. Thank you @Hugo.

I have the same purpose need to keep imp running for a long period.
Any dedicate codes added for avoid deep sleep?
Don’t know some how, my imp stop receive sensor data from Arduino?

Put this at the start of your device code:

server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_TIL_SENT, 10)

This will tell the imp to avoid deep sleep if it can’t contact the server, ie. if it goes offline. You can catch this event with this code:

`function serverOut(reason)
{
    // This function is called if the server connection is broken or re-established

    if (reason != SERVER_CONNECTED)
    {
        // If disconnected schedule an re-connection attempt in 5 mins (300 secs)
        imp.wakeup(300, function() {
            server.connect(serverOut, 30)
    	})
    }
}

server.onunexpecteddisconnect(serverOut)`

This calls serverOut() when a disconnection occurs. It sets up a reconnection attempt – using server.connect() - five minutes later. The result of that attempt will be a second call to serverOut(), when the attempt will have either timed out (still disconnected) or succeeded in contacting the server. If the device is connected, it will not attempt to re-connect again, unless at some time in the future it goes offline again.

Thanks! I modified the code process as :

server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_TIL_SENT, 10);

function readsensor {}
function serverOut() {}

server.onunexpecteddisconnect(serverOut);
readsensor();

is this correct? still can’t check the sensor data update?

Looks broadly right, but it’s hard to say without seeing readSensor() in full.

I reboot the device and it back online now.
Lets wait and see how long will it keeps running!

Thanks smittytone !

the process is keep going! great!