I am looking for some suggestions in regards to using the cloud API in the best possible way.
I have a webpage listing potentially tens/hundreds of devices fetched from the API. All of the devices would be with the same software and the same 5+ variables.
Calling separate API requests for each device variable seems unreasonable and slow. Even if the device variables are combined in a single concatenated value, the page would still end up with 100 requests for 100 devices.
The goal is to fetch the variable values along with the device info. Is there a possible way of doing so? What is the best practice in such a case?
Is there any “backend” database at all to your application or is it simply a front end web page and that web page only accessed data via the particle cloud API?
Also, does all users of your product access the same data from all devices within your product? Or does user A only want to see devices 123 where as User B only wants to see devices 456?
In my particular case, the device publishes data out to the cloud every x minutes. That data is primarily it’s latest readings from sensors. This data is stored in a backend SQL database. Then my front end will make an API call to my own backend for the latest sensor data. The backend assembles a JSON object for all devices being request and sends it back to my front end. This way in most scenarios I do not make API requests directly to particle. For me, data publish rate is 5 minutes. So anytime a user goes to the page it’s data being displayed was most times within 5 minutes from now.
If a user wants to take a reading “on demand”, I then use a particle function to access the data near instantaneously. This generally is only from one device from one user and not from the fleet of devices.
Does that help? I personally don’t even use particle variables although I’m sure they have their place.
Thanks for the feedback. The application has a backend DB but we tried to stay away from implementing a persistence layer for this and wanted to be more “real-time” data.
Not all the users would have access to the product devices, but that is managed on our side.
Just to clarify a Particle.variable()
is never sent but only their value requested via a HTTP GET
request (just as a Particle.function()
execution is requested via a HTTP POST
request).
If you want your devices to send/push data Particle.publish()
would be the way to go.
You can use Particle.subscribe()
on all devices to listen to a single event that causes all of them to publish their data.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.