Ahh, yeah that makes sense as a possibility. The other thing you can do to (somewhat) force double check your connectivity is to ping your networkâs RSSI. I do this to catch an otherwise uncaught bad connection state I discovered with the Electron (may also be applicable to Photon, but youâll have to double check the source code for what values are possible to return).
Just a note, at least for Electrons, this is actually making a call to the modem itself, so you donât want to constantly spam this. Thus, I just check it regularly. In your case, perhaps you can just check right before you publish, if you arenât publishing very frequently.
#if Wiring_Cellular
inline void particle_startup() { cellular_credentials_set("hologram", "", "", NULL); }
// Cell indicator Config
extern CellularSignal sig;
extern int strength;
#endif
int rssi = 0; // init as "network not ready"
uint32_t signal_strength_last_time = 0;
const uint32_t signal_strength_update_period = 500; //ms
void update_signal_strength() {
#if Wiring_Cellular
sig = Cellular.RSSI();
bool signal_ok = true;
if (rssi >= 0) signal_ok = false;
rssi = sig.rssi; // rssi is 0 if network not ready, 1 is error getting value (never returned), 2 is if modem returns 0 rssi aka really bad service
if (rssi >= 0 && Cellular.ready() && !signal_ok) {
// this is a problematic state where the system firmware doesn't
// realize that the modem is disconnected, just going to restart
Resets.reset_now(RESET_REASON_BAD_CONNECTION_STATE, true);
}
#elif Wiring_WiFi
rssi = WiFi.RSSI();
if (rssi >= 0 && WiFi.ready() == true) {
// this is a problematic state where the system firmware doesn't
// realize that the modem is disconnected, just going to restart
Resets.reset_now(RESET_REASON_BAD_CONNECTION_STATE, true);
}
#endif
signal_strength_last_time = millis();
}
// somewhere in loop()
if ((millis() - signal_strength_last_time) > signal_strength_update_period) update_signal_strength();
I also in my case wait to ensure that this bad state is present for two checks in a row, to avoid any transient state that recovers immediately. You can replicate this by delaying and checking twice for a one-shot check.
Of course, test in your use case. I havenât super thoroughly vetted this for Photons (it should be safe, just not sure if this issue exists with Photons or not).
Edit: especially if you have blocking code in your loop, it may be worth calling the below before checking if Particle.connected() == true
if you can afford the processing time:
delay(1000); // yield to system thread
Particle.process(); // fulfill any application thread cloud stuff that's waiting
if (Particle.connected()) {
...
}