Storing a Particle variable on the web

Hi I am just starting my first project with Particle and I have a question about best practice for storing a simple value from my particle app to the web.

Here’s the example I’m trying to get working:
I have a very simple web page interface that is turning on/off an LED on my Particle. On the page is a simple on/off switch and and a button that submits that input to the particle. Very simple, BUT – I want to save any changes so when I return to the web page the on/off button will show the current state of the LED. I want to minimize my Particle data usage, so instead of reading the values from my Particle each time, I want to store the on/off value on a web page or something. How should I do this?

I’m hoping for a simple solution to this, I don’t know anything about server programming or databases. I just want to store a simple value!

Any help is much appreciated

Perhaps disregarding the actual question, but

That’s rather ‘unreliable’. If, for whatever reason, the state on the device changes without interaction from that webpage, you’ll have a false state, which might not be desirable. Just wanted to put that out there for consideration.

@Moors7 Good point. Reliability probably outweighs a few extra kb in data usage. I will just get the values directly from the device. Thanks for the help.


Have you seen this old tutorial?

If you have function to set the value and variable to read it, you can do what you want.

1 Like

Great tutorial. If you were to reload the page would it show current position of the servo? Does it read that data from the Particle?

Yes, but you don’t even need to reload the page–it does it automatically. The setInterval call on the web page re-reads the current variable value every second and refreshes the page. One read per second is about the practical lower limit–you can’t really go much faster than that.


You could make it so that it retrieves the value on loading the page and then subscribes to events to listen to publish messages from the device, That way, you won’t have to poll continuously, saving on data.