The issue: One of our remote devices this week was stuck flashing cyan (i.e. lost connection to the cloud) and non responsive to any cloud interactions and failed to send its weekly SMS (sms are not sent via the cloud).
The concerns:
- The software watchdog didn’t kick in (it was set to 60 seconds).
- It was fixed with a simple power restart.
- Non-cloud code failed to operate (3rd party SIM SMS’s)
- The device was in Multi-threaded mode
The current challenge:
How do we prevent Cloud connectivity loss from blocking non-cloud code from running and/or to trigger a restart to give the device a chance to recover from being blocked from the cloud?
Initial thought:
- Run some checking code every few minutes to see if the Cloud is disconnected, if so - restart the device. But I’m not sure this will work, given the watchdog didn’t trigger and other non-cloud services didn’t trigger.
Open to suggestions, ideas if others have built in other ‘error handling’ code.
My current thoughts below, but it isn’t quite there yet.
int countOfNotConnected = 0;
int maxCountOfNotConnectedBeforeRestart = 100;
int timeBetweenCloudConnectionChecks = 30; //in seconds
int timeOfLastCloudConnectionCheck = 0;
void cloudConnectionCheck()
{
if ((timeOfLastCloudConnectionCheck + timeBetweenCloudConnectionChecks) < Time.now())
{
if(Particle.connected() == false)
{
countOfNotConnected = countOfNotConnected + 1;
}
else
{
countOfNotConnected = 0;
}
timeOfLastCloudConnectionCheck = Time.now();
}
if (countOfNotConnected >= maxCountOfNotConnectedBeforeRestart)
{
countOfNotConnected = 0;
System.reset();
}
}