Photon deep sleep question

Is there any difference in code execution when Photon is first time powered up versus wake up from the deep sleep?

I do not believe there is. It should run all the startup code and setup() just like it was being powered on. The main difference is there should be a different “reset reason” set and retained memory will stay in place rather than being zeroed out.

Hi, how are you doing the deep sleep?
I think one of the options continues the code from where it left off, but I do not know much more than that :neutral_face:

There are some minor differences:

  • the reset reason will differ (as pointed out by @HEng)
  • retained variables (Backup RAM) will be initialised on cold start but retained after deep sleep and reset
  • depending on the way you sent your device to sleep the power up of the radio module may be different (i.e. on Electron when using SLEEP_NETWORK_STANDBY)
1 Like

@Peter75, @gusgonnet, the Deep Sleep on the Photon will reset the STM32 when it wakes. The difference between a “power up” vs a “wake from deep sleep” is that the former resets all hardware on the Photon since it is an application of power (aka hard reset) whereas the latter only causes the STM32 (not the WiFi module) to do a soft reset. There are conditions that could occur under which the STM32 or the WiFi hardware will not recover unless power is removed and re-applied. This is why an external watchdog which controls power to the Photon can be important to use for high-reliability applications.

4 Likes

Thank you very much for various suggestions. I follow HEng’s advice: include the new sleep.result class and add a check for the wakeup.reason in the setup(). If WAKEUP_REASON_NONE, then I execute one set of code, else execute other set of code. It seems to work quite well. Thank you very much for everyone’s hep!!