Reading variables from python

I’m working on a home lighting automation project using photons to measure motion, light, proximity, etc. around my house. I’m using a raspberry pi to run a local server, read variables, make decisions about light levels, and send commands to my Philips hue terminal. I’ve got the photons talking to my local server, and a python program talking to the bulbs.

The one thing I’m struggling with is how to read the photon variables in the python program. I can issue a get command at the CLI to get variables, but I’m not sure how to use that data within my light control program. I’ve done some searching and haven’t found any great examples. Can anyone point me to a good example / tutorial that shows how to read and store particle variables in a python program?

I had to work out how to control a function which , reading a variable is the easy bit , this is my post.

Thanks, this has gotten me further down the trail. I’ve got my raspberry pi retrieving variables from the particle cloud within python using spyrk. Now the last piece of the puzzle is getting spyrk to talk to my local server instead of the cloud.

I’ve tried changing the api from

spark_api = Hammock('')


spark_api = Hammock('')


spark_api = Hammock('')

no luck. I’ve tried a couple of other python API’s too. I’ll keep messing with the code but I’m not really sure where to start. I guess I can move forward just getting the variables from the cloud, but I’d rather not have my lights dependent on an internet connection.

Not installed the local cloud server, I only know how to read variables and post to functions from using their api , so can’t say how to connect to a local server .
How did you come up with the port numbers 10 and 8080 ?
Also if their server uses https and not plain old http have you tried that ?.

If you are trying to talk to your photon / core directly using the api ? , you can`t do that ?
If you want to talk to the photon / core direct you need to install a server code on you photon/core.

So I have a number of photons around the house logging room temperatures and such like.

I use httpclient (library) to log data directly to a flask setup on a VM

More on flask here:

So, basically, every 10 seconds I log the data as JSON to flask. Flask takes the data and sends it (using a stored SQL procedure to a table in a MySQL instance).

It’s still a work in progress, but it does work quite well and it’s both flexible and resilient (so far).

@specialcircumstances That is the problem with Photon’s , they are like wheatabix you can’t just have one , so far I have 3 , 2 which are logging temperature etc around the house , 1 which I use for test projects and I want a couple more .
WOW , a 10 seconds log , I log every 15 minutes that`s starting to get large after only a couple of months.

I lied. looks like this actually worked:

spark_api = Hammock('')

10 comes from the static ip I set my local server to. 8080 is the port or something, I don’t really know. I saw it from another tutorial. Whatever, it works.

Photoresistor talks to photon talks to raspberry pi talks to python talks to phillips hue talks to bulb. Got it working!!! BOOYAH BABY! Now the fun beings…