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?
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.
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?
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
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.
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:
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: