Reset Pin vs Power Loss

I’m wondering about the difference between the Photon losing power and what happens to its variables and when you use the reset pin to force a restart.

At the beginning of my script I set a boolean flag to do an initial state publish if the flag is ‘false’. I then set the flag to true once the publish is done. So it’s a fire once sort of thing.

If power is pulled and then restored say half an hour later, the Photon doesn’t do the initial publish. Presumably because it somehow remembers the boolean variable state.
However, if I reset using the button, I get the initial publish.

Weird? Or?

Unless you are using Backup SRAM (retained variables), then there should not really be any difference.
However even if you did, the symptoms would be the other way round as a reset would not clear the variable but a power-loss always will - and in case of a brown-out (although rarely) might even erase some portions of flash memory.

But don’t forget to think down other lines of possible causes. Without actually knowing your code I’d first think of a timing issue. Cold connects usually take slightly longer than warm connects due to the fact that the WiFi module won’t be completely reset while the µC is.

If you are using SYSTEM_THREAD(ENABLED) that split second might
make the difference between having a publish happen or not.
In your stripped down code in your other thread, you don’t check whether or not a connection was established before attempting to publish, but you should. If you happen to find you’re not connected, you may indicate the fact either via Serial.print, an LED flash or any other means or just wait and retry.

1 Like