I’m building a web app and am interested in what peoples experiences have been with using a GET approach vs an event listener from the perspective of the web app.
I started off using Spark.getVariable from the JS library (I know this should read Particle.getVariable, but I’m not sure if it’s been deprecated yet).
Anyway, I’m using the JS setTimeout function to call the getVariable routine on a bunch of variables about every 10 seconds. I recall setTimeout at the end of the GET routine so that I’m not potentially queuing up requests if for any reason it takes longer than 10 seconds to fetch all my variables.
This all works pretty well until I take the device offline. When this happens I would ideally like the web app to handle things gracefully and alert the user that the device has gone offline as soon as ‘device.connected’ is able to tell that it has.
However right now as soon as the device goes offline I get a whole lot of queued up GET requests which can take quite a while before they return a 408.
For some reason after numerous 408’s I don’t think the Spark.listDevices call works anymore, which pretty much means that my webpage more or less just grinds to a halt after I take a device offline.
I had considered switching to the ‘push’ methodology of just using spark.subscribe (and Particle.publish on the device). However it seems a bit of a waste to be pushing data onto the internet when the web page may only be used once a week for example.
Any ideas would be great