Pull data to photon to populate variable

I have a few variables (time zone, etc) that I want to be able to specify per-device. Is there an easy way to store this external to the Photon, and have it use something like a webhook to pull the data into the photon? Right now I’m using if statements for each System.deviceID() and matching that way, but that requires new code for each new device. Not a huge deal since this is a small project, but definitely not ideal.

Is there documentation or tutorials on configuring an external web server to service webhook requests from the Photon?

Do you need this to be a secure connection (HTTPS), or would a HTTP GET request to your server be ok? If the latter is ok, then you could do it without webhooks. You could include the deviceID in the query string of the GET request. You can get that from System.deviceID(), so the code could be the same on all devices.

You could even do this without a server if you use another Photon to act as the provider of the data to the devices you want updated. The devices (the ones needing to have their variable populated) would do a Particle.publish with their deviceID as the data, to which your “server” Photon would subscribe. That Photon would then publish an event whose name would be the deviceID of the one you want to receive the data, with the data being what you want to populate the variable with (and each device would subscribe to an event whose name is their own deviceID).

HTTP is fine, no sensitive data at all. Using another Photon… that’s genius. I would need to update the code on that one photon any time I wanted to change the data it replies with though, right? I have quite a few photons in permanent install around my house (like this one) so I could piggyback code onto that one to service replies.

As far as HTTP GETs are concerned, do you know of any tutorials that could get me started in the right direction?

What’s wrong with using Particle.functions with EEPROM to set settings? That wouldn’t require code updates, but would give you the ability to edit settings remotely.

1 Like

I don’t know of any tutorials, but you can look at the code in the Application.cpp file in the HTTPClient library. That would give you the Photon end of things, but I don’t know about the server end, since I’m not a web programmer.

What’s wrong with using Particle.functions with EEPROM to set settings? That wouldn’t require code updates, but would give you the ability to edit settings remotely.

Interesting. How would I go about remotely changing variables stored to EEPROM? I am aware of the functions baked into the Photon to manipulate them.

I assumed in my answer, that you wanted to initiate the update of the variables from the devices with those variables, which is why I suggested the publish/subscribe paradigm. It that’s not true, if it’s ok that the server (whether that’s a web server or a Photon) initiates the transfer, then using Particle.functions would be simpler. So, which way do you want to do it?

Whether you store the values in EEPROM or not is really a separate issue.