I have a small fleet of Particle photons. I use them, love them, they’re an integral of my daily tech.
Now, why oh why for example, you have a bug in your code and the device goes into SOS mode, does the device reboot and run the same code again? What’s s the actual logic in this? If the code is broken, notify the user, and reboot into safe mode, don’t run it again!
The reason I ask is that essentially, you would need to ensure that there is always physical access to your device. What if it was installed in a ceiling for a sensor, or you installed an LED controller in a friends house, and they wanted something tweaked, you cant safely do that without the client potentially having to intervene without having someone [who may not be technically minded] to hold down one button, then when the light flashes…then…it all seems a bit peculiar that no one has asked for this before. Or does anyone know a snippet of code I can put in my scripts that may be able to do this?
Sadly I am not experienced enough to write my own firmware, nor would I know where to start, although I assume it would not be too hard to move to safe mode instead of reboot. If we look at the following diagram we can see:
I don’t create block diagrams often
If we look past that, the issue requires the presence of a person to physically intervene and break that loop. My thinking is, what if no one is present? You have a device stuck potentially that you may not be able to do anything about.
As developers, we deal with logic, and surely the second diagram makes for more logical sense than the first? What is the purpose of the particle rebooting, running code that doesn’t work.
However, the other scenario that results in a SOS is an intermittent fault, such as memory corruption or a random bug in code. This might only occur after a long running time, and goes away, at least temporarily. Going into safe mode in that case will result in your firmware not running and would require someone to flash new firmware to it to get it out of safe mode. This would become unworkable for large fleets of devices.
However, if you really want that behavior during development, check the reset reason using System.resetReason() in setup(). If it’s RESET_REASON_PANIC, call System.enterSafeMode(). You probably want to also use SYSTEM_THREAD(ENABLED) so this happens immediately at startup.
rickkas You are my saviour! That’s just what I was looking for. Appreciate this snippet of code. Thanks for your help on this matter. This will save a lot of aggravation in the future for me.