Better check than Particle.connected()?

Hey everyone!

Does anyone know of a better check than if(Particle.connected())?
I find pretty often that my electron will pass this check but then when I publish without Acknowledgements, the publish doesn’t reach the cloud.
Only fix is to reconnect… but how do I know when it needs to reconnect!?


1 Like

In a certain sense, the problem is unsolvable. The Electron doesn’t really keep a connection open per se, because doing so would use data even when idle. It only pings the cloud every 23 minutes (when using the Particle SIM) so it really has no idea if it’s really online any time in that 23 minute period.

Particle.connected reflects the state the Electron believes the connection is probably in, but can’t know if it’s really connected or not until the next time it sends data or a ping. Particle.connected() doesn’t query the modem or use any data, which is why you can call Particle.connected really often.

You could set the keepAlive much lower, for example if it was 30 seconds you would know if you were able to send and receive data in the last 30 seconds. But each keep alive uses 122 bytes, so that’s probably not practical with the Particle SIM.

You could check Cellular.RSSI(). If the RSSI is < -100 (or 0) then you probably have a really weak signal and the send may fail. Still no guarantee, but is not a bad check.

1 Like

ok that’s fair enough I guess… thanks for that… will add in the RSSI and see if it can give me any more info… it seems that without having using with_ACK in publish it’s a little tricky to know the real connection status…