Device returned status not correct

When I send a GET request to my device it returns a value called connected, which i’m assuming is the status of the state of connection for the device. It seems to always return true. Also the device shows in the particle mobile app as connected. All this while the device is unplugged and battery is unplugged. Has anybody else seen this behavior. Seems kind of unreliable as to get the online status of the device. Please help.

@crustache, what “device” are you referring to - Photon or Electron?

Sorry, It’s an electron

That’s a common behaviour and is frequently discussed and explained in this forum, so I’ll do it again.

The Electron uses connectionless UDP to save on data while the WiFi devices use TCP and can “permanently” ping the cloud.
So it’s easy to actually know if a WiFi device is online while for a cellular device it’s not that easy since not having a connection is standard for connectionless UDP and thus can’t be used to distinguish between really connected or just not knowing.

Granted, it might be less confusing to assume (and reporting) the device is not online, but the only way out of not knowing either would be to try accessing the device. If it responds it’s not offline :wink:

Hmmm, well that’s the thing. How would I directly query the device because I use the api which queries particle.io and it reports a status of connected, which doesn’t seem to help me at all because i know it’s not connected yet the response is that it is.

If you have a Particle.function() (POST “requestable”) or Particle.variable() (GET requestable) in your app firmware, you’ll only get a valid response if the device is online.

Right, I thought I could utilize a function that was already present. I didn’t want to cobble together a cron job or something to query the device for availability. But it looks like that’s the only reliable method. Thanks.

There is also a last_heard field in that response, which tells you when the last active communication happened between cloud and device.
Maybe you could utilize that?

1 Like

Just to be clear: what you want is there already for Core and Photon over TCP. It is Electron over UDP that requires more work on your part.

1 Like

Yup! Hence the earlier post :wink:

1 Like

This sounds like it might be more useful, will just require some logic server side i suppose. thanks.

1 Like