Imp wakes from "deepsleep" - does it automatically download new code?

We have numerous Imps running on the same model. The Imps deep sleep for 2 minutes and then reconnect to their agent.

IDE documentation says “others are still running the previous build and will do until they are either power-cycled or you select each one and click on the ‘Build and Run’ button”.

Question is: when the imp reconnects after deep sleep will it download new code ? Or must it be individually selected and the “Build and Run” button clicked ?


Yes it will get new code on wake from deep sleep (when it connects). You must have saved the code though (by using build & run), but not for each device individually.

Note you need to be using onidle() before sleeping to ensure the device processes incoming packets from the server (eg the ones telling it there’s new firmware available).

Thx Hugo …

Does this code seem right ?

function touchServerAndDeepSleep() { // As much as possible we want the imp cold and dark agent.send("recordVolts", hardware.voltage()); server.expectonlinein(localState.sleepTime); imp.onidle(function() { imp.deepsleepfor(localState.sleepTime); }); }
… which is called by:


No, expectonlinein() will disconnect the imp before it manages to check for code.

Drop that line and change the imp.deepsleepfor() to a server.sleepfor() call.

Note that touchServerAndDeepSleep() will RETURN. The sleep won’t happen until the imp is next idle, which is not until the current execution context is done, as onidle() just registers a handler. A lot of people don’t get this bit and it causes some very confusing bugs!

Excellent ! That fixed the problem - the code wasn’t updating consistently across all devices - that’s why I asked the question.

Thanks much Hugo !


Does this doc example have the same problem of not making sure to proces incoming packets:

After wake I think the imp will first connect at agent.send and then disconnect at server.expectonlinein ?

In that example, after deep sleep the imp wakes. WiFi is off until the code reaches agent.send() in log() then deep sleeps at imp.deepsleepfor(), not server.expectedonlinein()