I’m trying to use someone else’s code: [code]local http=require(“socket.http”)
local auroraToken = “xxxxxxxxxxxxxxxxxxxxxxx”;
local siteurl = “http://192.168.x.xx:16021/api/v1/“..auroraToken..”/state/on/”
local siteurl1 = “http://192.168.x.xx:16021/api/v1/“..auroraToken..”/state/”
local respback = { }
local res, code, response_headers, status = http.request
{
url = siteurl,
method = “GET”,
headers =
{
[“Content-Type”] = “application/json”
},
sink = ltn12.sink.table(respback)
}
if tonumber(code) == 200
then
for key,value in pairs(respback) do
auroraOn = string.match(value, “%a+”, 8)
end
end
if auroraOn == ‘false’
then auroraOn = ‘true’
else
auroraOn = ‘false’
end
local payload = ‘{“on” : {“value”:’…auroraOn…‘}}’
print(payload)
local respback = { }
local res, code, response_headers, status = http.request
{
url = siteurl1,
method = “PUT”,
headers =
{
[“Content-Type”] = “application/json”,
[“Content-Length”] = payload:len()
},
source = ltn12.source.string(payload),
sink = ltn12.sink.table(respback)
}[/code]
It runs fine in the developer mode (in that it says it runs), but it doesn’t do anything. I believe the line “if tonumber(code) == 200” means that if the response code is 200 do what is next. Running the code in another language I get a 202 return code. Should I change the 200 to 202, or is there something I can put in runs the if statement no matter the code returned?