Post Method

Please excuse what is quite probably a very simple question to answer, but I’ve been searching in circles. I’ve probably seen most of what I need, but wouldn’t recognize it if I did. I’m looking for a simple way to pass a device state through an http post method For example, I’d like to pass a thermostat temperature every X minutes. I figure I can handle the timer through a scene, and have the scene handle the post through code.

I’m assuming that I use a variation of this:

local http = require("socket.http")
http.TIMEOUT = 5
result, status = http.request("http://192.168.0.113/runprocess.htm", "run=run")

The server that accepts the post:

http://api.thingspeak.com/update?key=MYAPIKEY&field1=0

Adding 1 plus 2, I get 3:

local http = require("socket.http")
http.TIMEOUT = 5
result, status = http.request("http://api.thingspeak.com/update?key=MYAPIKEY&field1=TEMP", "run=run")

How do I get the temperature into ‘TEMP’? I know that I need to query it. This is the code I would use for Variable Container:

local lul_utemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", 29)
luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable2",lul_utemp, 45)

So now I add 3 and 4 and I get this:

local lul_utemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature", 29)
luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable2",lul_utemp, 45)

local http = require("socket.http")
http.TIMEOUT = 5
result, status = http.request("http://api.thingspeak.com/update?key=MYAPIKEY&field1=TEMP", "run=run")

This is where I get stuck. I suspect that I’ve got extra stuff in here and I’ve no idea if I have everything I need. Plus I can’t figure out how to get CurrentTemperature into the URL string.

Any help would be most appreciated.

Have a look at the code on this page and see if it helps - particularly the bit where the URL is constructed.

http://forum.micasaverde.com/index.php/topic,13781.0/topicseen.html

Also do you the need the temperature showing in the Variable container. It also helps if you name your variables something meaningful like fridgeTemperature. If you are testing this in the Apps–>Develop Apps test area - you always need to finish the code with: return true

[quote=“a-lurker, post:2, topic:174414”]Have a look at the code on this page and see if it helps - particularly the bit where the URL is constructed.

http://forum.micasaverde.com/index.php/topic,13781.0/topicseen.html

Also do you the need the temperature showing in the Variable container. It also helps if you name your variables something meaningful like fridgeTemperature. If you are testing this in the Apps–>Develop Apps test area - you always need to finish the code with: return true[/quote]

Thanks very much. This helps a great deal. I’ll call my variable ‘UPTEMP’. The URL bit helps a great deal as well.

It also occurs to me that I never set my variable to the device state so I need to make ‘UPTEMP’ = ‘CurrentTemperature’.

Now I have this:

local UPTEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 29)

local http = require("socket.http")
http.TIMEOUT = 5
result, status = http.request("http://api.thingspeak.com/update?key=MYAPIKEY&field1="..UPTEMP.."", "run=run")

Which works fabulously.

Thanks very much!
Dave