Imp.deepsleepfor - where does code resume after this?

hi all. I am finally getting around to trying some power saving with imp. I am having some trouble understanding how this call works.

It does not seem that the entire script runs from the start (cold boot) when the imp wakes up but it somehow seems to be resuming its prior actions.

does it resume to this: server.onunexpecteddisconnect

are the wakeups preserved?

sorry, I know a series of experiments may lead me to the answers but at the moment I feel like I must be missing something more obvious.


It’s like server.sleepfor() - the script will start from the top at wake time, however if you use imp.deepsleepfor() then your code will be running without any wifi connection. If you have the default connection policy set, then the first thing that tries to talk to the server will bring the connection up.

Nothing is preserved apart from the nv table as you have been in 4uA sleep mode.

thanks for the quick response.

Where is the best documentation to describe this? I have seen the wifi state diagram but it is a little hard to interpret. Are there other flowcharts that would explain the deep sleep sequence?

Looks like one would use hardware.wakereason() to branch code on cold boot versus waking from sleep. Is that correct?

How to run an imp offline has a section on Deep Sleep which you might find useful, @mjkuwp94

awesome! thanks.

let me take a moment to thank you for this and all of the other new documentation that has been coming online recently. It is much needed and it is also really well done. I have used some of these new references to great advantage.

For this question about deep sleep, it looks like it will take a pretty big effort to understand this all and do it correctly. What would really help a lot is a flowchart - or several of them laying out different examples. All that text can be read and digested but there is a lot to it.

One possibly simple question. A lot has been written about telling the server the device is going to disconnect and be ‘expected online’ at some time in the future. In my design the waking will be done by a rising edge on the wake pin. I am uncertain what to do with the server for that situation. The server should expect the device online in anything from 30 seconds in the future to many days in the future. Will this work?