Pinging multiple devices in one go in order to get their online status

Greetings everyone,

Context
I’m working on a project that involves 100+ particle devices which all are connected to the Cloud API. Those devices are either registered under various products or live under the /devices namespace.

Problem
Currently I have to build a web analytics dashboard which shows how many devices are online and how many are offline/no signal.

Is there a way to fetch or ping all the devices in one go, instead of iterating through each device under a product and pinging it individually?

Have you tried Particle.publish()?
For devices under one product or “devices” account this should work.

Hi, if you are using JS for your Web App you can use
particle.listDevices({ auth: token}); to get an array of your devices and one key in arrays object elements is “online” so you can easy distinguish which one is online which is offline.
Function call give even more info about your devices in one call.
https://docs.particle.io/reference/SDKs/javascript/#listdevices-1

something like this should print your devices list to console:

<!DOCTYPE html>
<html>
.......
............

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/particle-api-js@8/dist/particle.min.js"></script>

<script>
var particle = new Particle();

function getListDev(){
var devicesPr = particle.listDevices({ auth: token});
devicesPr.then(
  function(devices){
    console.log('Devices: ', devices.body);
    },
  function(err) {
    console.log('List devices call failed: ', err);
  });

}
................
..........
.......
</script>
</html>

Here is an example of my webapp which call particle.listDevices and put some info in to the table

3 Likes

Hey there,

This would imply updating the firmware and all the particle devices, right?
I also skimmed through the device particle API and saw this call: Device OS API | Reference Documentation | Particle which would come in handy, but currently am trying to find a Cloud API-only solution

Hello,

Yes this is the approach I have been using up until now, but noticed that the online and last_handshake fields don’t change in real time, there’s a rather perceivable latency to them.

Yup, you are absolutely right which I noticed regarding to last_heard here:

I used getDevice() instead as nobody from Particle didn’t back to me with a solution.
But getDevice() and then iterate all over more than +100 will not work for you.
So honestly I don’t have any Idea how you can get accurate info with one call and looks like particle.listDevices() it’s useless when is not updating in real time :frowning:

1 Like