For a Gen 3 device in Automatic mode with System Thread enabled. What happens if the device is our of cell service for extended periods of time, weeks and months. Will the device continue to run the firmware correctly. Is there anything I need to be aware of here?
The device will continue retrying forever. Every 10 minutes it will reset the cellular modem but the device itself will continue running and will not reboot.
If there's no service there won't be any damage from doing this, though if you are using battery it will use a lot of power attempting to connect continuously. The status LED will also be blinking green all of the time.
Somehow I had overlooked the power hungry aspect of this. I will try an manage the connection manually. In semiautomatic mode, can anyone see any issues with using the following to manage this:
void periodicConnection() {
// Configuration Constants
const unsigned long CYCLE_INTERVAL = 60000 * 60 * 4; // (Interval between attempts)
const unsigned long CONNECT_TIMEOUT = 60000 * 11; // (Max time to try connecting)
const unsigned long STAY_ONLINE_TIME = 60000 * 60 * 4; // (Time to stay online)
// State Tracking Variables (static keeps them in memory)
static int state = 0;
static unsigned long lastCycleStart = 0;
static unsigned long stateStartTime = 0;
unsigned long currentMillis = millis();
switch (state) {
// --- STATE 0: IDLE (Waiting for the next cycle) ---
case 0:
if (currentMillis - lastCycleStart >= CYCLE_INTERVAL) {
lastCycleStart = currentMillis; // Mark the start of the new cycle
stateStartTime = currentMillis; // Start the timer for the connection attempt
if (Cellular.isOff();)
{
Cellular.on();
}
Particle.connect(); // Start connecting
state = 1; // Move to 'Connecting' state
}
break;
// --- STATE 1: CONNECTING (Waiting up to 11 mins) ---
case 1:
// A: Success - We are connected
if (Particle.connected()) {
stateStartTime = currentMillis; // Reset timer to count the 1 hour
state = 2; // Move to 'Staying Online' state
}
// B: Failure - We timed out (11 mins passed)
else if (currentMillis - stateStartTime >= CONNECT_TIMEOUT) {
Particle.disconnect();
Cellular.off();
state = 0; // Go back to sleep/idle
}
break;
// --- STATE 2: STAYING ONLINE (Waiting 1 hour) ---
case 2:
// Ensure we process background tasks so the connection doesn't drop
if (Particle.connected() == false) {
Particle.connect(); // Re-connect if we dropped unexpectedly
}
// Check if the 1 hour is up
if (currentMillis - stateStartTime >= STAY_ONLINE_TIME) {
Particle.disconnect();
Cellular.off();
state = 0; // Cycle complete, go back to idle
}
break;
}
}