Device downloads the new code but doesn't flash


I cannot flash the device without reseting it (power off then power on). The server logs shows that the device downloads the new code but the old one stays effective afterwards.

This is my code:

`function execute() {
if (hardware.wakereason() == WAKEREASON_TIMER) {
// poll and send things
else {
// do nothing and go to deep sleep
imp.wakeup(0.0, function () {
imp.deepsleepuntil(date(time(), ‘u’).hour, date(time(), ‘u’).min + 1, 0);


Is this if-else condition preventing the IMP to flash with the new code?

Thanks in advance,

The imp.wakeup(0, …sleep…) is putting the device to sleep before the new code arrives. If you used imp.onidle(…sleep…) instead, there are special measures to ensure that any new code arrives before the sleeop happens.


Due to some constraints on my code, I was not able to use imp.onidle(…sleep…).
Is there any way to let the device download the code and flash before sleep without imp.onidle(…sleep…)?

Can you say what these constraints are? It should be possible to use this in any code.