I am building a device based on the Electron which I will need to deploy within a week in a remote location.
Everything seems to be working fine, except that sometimes - after a period of bad connectivity - the Electron get stuck in listening mode (blue flashing) and the only way to get it out of this mode is by manually pressing the reset button.
Obviously this is a problem for a remote device, as there will be nobody there to press the button, so it will stay in listening mode forever - basically becoming useless.
I have seen this issue mentioned on GitHub (https://github.com/spark/firmware/issues/687) and a fix was planned for 0.6.x, unfortunately I need to do something about this before I deploy next week.
I was suggested there to create a listener on the listening mode and if the device is in that mode for long, then issue a reset.
I have done this, but it seems it is not working, as after another period of bad connectivity my device got stuck in listening mode again.
Below is part of my code responsible for the listening mode reset and for putting the device in sleep (which - I have a feeling - might influence it).
Any idea why my event handler doesn’t kick in and restarts the device after being in listening mode now for hours?
void setup_mode_handler(system_event_t event, int ms_passed) {
// to prevent being stuck in setup mode, after 3 mins in setup mode, let's restart
if (ms_passed > 3*60000UL) {
System.reset();
}
}
void setup() {
Serial.begin(38400);
pinMode(battery_relay_pin, OUTPUT);
// register the setup mode handler - to handle when we get stuck in setup mode
System.on(setup_update, setup_mode_handler);
}
viod loop() {
if (msg_id <= msg_num_restart) {
Serial.println("Going to normal sleep (does not turn off the network).");
System.sleep(D1, RISING, sleepInterval*60, SLEEP_NETWORK_STANDBY); // Does not turn off network
}
else {
Serial.println("Going to deep sleep (turns off the network, restarting the process with from 'setup()').");
System.sleep(SLEEP_MODE_DEEP, sleepInterval*60);
}
}