Dashboard Presence Indicator

Hi

How can I implement a presence indicator for my web app as seen on the new Dashboard? I presume I will have to either poll the devices, or, more probably, get each device to ‘ping’ the cloud. Is this how the dashboard presence works?

Thanks

Kevin

Actually, the Cloud will broadcast an “online/offline” SSE, which you can see in the dashboard if you reset your device. You can use these two events to trigger an indicator.

1 Like

I think the dashboard uses an api request to your devices (eg /devices/) to check the state of the “online” or “connected” variable

Instead of guessing, we could just try asking the people who built it :wink: @jeiden, could you help out here :)?

Is the dashboard code on GitHub?

Hey @Kevin, thanks for reaching out. I’m Jeff, one of the engineers behind the Dashboard. There is, in fact, an server-sent events (SSE) endpoint that you can hit in your own code, or on the command line, to give you the exact same data as the dashboard uses.

To find this endpoint visit the logs page of your dashboard and look for the code icon next to the pause button:

Clicking this button will reveal the exact endpoint that your dashboard uses for its data, including your access token:

The base of the endpoint will alwasy be api.particle.io/v1/devices/events. The code for the dashboard is unfortunately not available on GitHub, as it is a private repo. Does this help @Kevin?

3 Likes

Also, after talking with @Moors7, I think I better understand what you’re trying to do: replicate the real-time online/offline indicator. In this case, you should get a list of your devices using api.particle.io/v1/devices, then use the sse endpoint described above to catch online and offline events for your devices

1 Like

Thank you - this works well for all my devices and for my custom dashboard.

I also want to display online/offline in a users mobile app (just their device) - can I set up a callback for a specific device?

You can compare the device ID to see if it matches with the one registered with the account.

I initially though of that, but not efficient if you have 100’s of devices… not a problem right now though, so if no other option I will use this for now. Thank you

Well, somewhere, something has to do a comparison. Callback or not, something has to check whether a given ID matches with one you’ve set up. You could also setup individual listeners, but that might be even less efficient.
Then again, there might be better options I haven’t thought of, so alternatives are appreciated.

Hi @Kevin!

You can filter for a type of event, and watch all the events in aggregate from all your devices. All the online/offline events are prefixed with “spark” since they’re system events, try this url:

https://api.particle.io/v1/devices/events/spark?access_token=YOUR_ACCESS_TOKEN

Then restart one of your devices, you’ll see the event come through. If you want to know what devices are already online/offline, look for the “connected” property on your device list endpoint here:

https://api.particle.io/v1/devices/?access_token=YOUR_ACCESS_TOKEN

Thanks!
David

2 Likes

Thanks All. Got something useful to work with your assistance.

2 Likes