Started this topic to try and capture everything and anything people have found that makes deep sleep reliable, or things to look for when it's not.
From trawling the net for days, it seems that everyone has the same experience as me - sometimes you can get reliable units that work for months, and other times they just never come back.
I've just pulled the very latest NonOS repo and it seems to have made my units fail to come back almost immediately (it also broke my SSL but that's another story - FYI Espressif have re-enabled SSL3). I didn't spend much time, I just rolled back, but I want to try and put some science around this black art.
For my own experience right now, when a unit fails to come back properly from deep sleep it actually attempts to boot, but it never makes it into userland, and you can't hit the reset button you have to unplug it completely for a bit. It will also not respond to flashing.
So here are the things I have found that will stop units from coming back from deep sleep, from the obvious to the not so obvious:
- you have to wire up the connection. Seems obvious but I got tricked by this on some Electrodragon modules. The circuit showed it was wired but the board wasn't
- don't use a resistor, use a diode, preferably a Schottky. When your power is not reliable a resistor can give unpredictable results
- put a short delay after the system_deep_sleep call. Adding even os_delay_us(100); can make a difference
- shut down your wifi and clear your UART before calling deep sleep. The routine does it, but it waits till your UART buffer is empty and seems to maybe almost wait till the wifi is off but if it's not well and truly off it causes problems. At worst it causes delays you may not have figured into any timing calculations
- don't trust the RTC clock to wake you at the right time. The clock is highly temperature dependent and the moment you go into deep sleep it starts to cool down and the time drifts. Mostly it seems to wake the unit early, so my approach is to get the correct time via NTP and always use that. Since the maximum deep sleep time is approximately 3.5 hours, the drift isn't usually huge and this works well for me. I also use a moving average that takes into account the difference between the event time and the time the unit gets into run mode, and I use that to correct my sleep time value, so my units quite quickly adjust to waking up really very accurately
- make sure your power supply can handle the current surge at start up. If your power supply is not quite right and don't have enough current then it won't wake up properly
- change the RF calibration settings on wake using set_deep_sleep_option. If you can get away with not doing a full calibration every time you wake up, then change the setting and it will significantly decrease the initial current draw. This may help with the tip above
So they are the things I know about - one other thing I suspect but am in the process of testing is use of I2S or DMA interrupts. I have a feeling this may be messing me up and that if you have DMA running and ISRs being called for any of your peripherals like HSPI or I2S then that may mess things up. I'd like to hear your opinions.
OK so that's me.... and.... GO!!