Ping returns random result

Using example from Electron-Reference-Cloud API-devices-ping

curl https://api.particle.io/v1/devices/0123456789abcdef01234567/ping
-X PUT
-d access_token=1234
Results appear random. The Electron is sitting in a box, no power, no antenna
online:false
online:true
online:false
online:false
online:true

Mac or Windoz same result. I need a reliable way to check if my device is online or not!

Calling a function or requesting a variable is often a more reliable method to check the sate due to the protocols used. For electrons the online/offline status can be discarded, and the last-seen time should be referenced to get an idea of when it was online last.

Requesting a variable may take multiple calls before a variable is returned. The “bummer” message may happen a few times and then on try N, it works. I need to know within 5 minutes if a monitor is truly offline. Further suggestions?

The Electron does not maintain a connection to the cloud, so there is no online/offline state. This is done to conserve data. It only communicates when there is data to be sent or received (publish or subscribe), a function or variable request, a ping, OTA flash, or every 23 minutes (keep-alive).

Thus any time within 23 minute (with the Particle SIM) interval, the device could go away and the cloud side would not know.

Ping should never return a false positive (reported online when it’s not). If you have a reproducible failure case for that, submit a support ticket with the device ID that is offline, but being reported as online and we can try to reproduce and check the cloud logs.

Ping can return a false negative, reporting offline when the device is online, because the ping packets did not make it to the Electron. This is unavoidable on cellular networks.

The best method is generally to publish from the device periodically. If you don’t get the values from the device, it’s probably offline. You can monitor the event stream using webhooks or the SSE event stream. This method is scaleable to many devices, ping is not because you’ll hit the API request limit eventually.

1 Like

Thanks for the SSE suggestion. Scaling is important to us and we will work with implementing that.
I find the ping problem very repeatable so I’ll open a ticket for that.
Regards