Help required
I've been struggling to write a lua script to correct some xively data which is not correct. I'm having terrible trouble getting it to work. Perhaps someone could spot what I'm doing wrong. Any help appreciated.
The idea is to update the data points on feed id 8 with data that is more realistic. (My 1 wire bus went belly up and reported
a temperature of 85 degrees for 20 minutes)
Here is the script which I was hoping would update the feed. (Just a couple of minutes worth at a time)
require("xap")
require('ltn12')
local socket = require("socket")
local http = require("socket.http")
local XivelyID = 461052594
local XivelyKey = "jny---*****---xzni1R"
local XivelyURL = "https://api.xively.com/v2/feeds/"
function init()
local json_data = string.format(
[[{
"version":"1.0.0",
"datastreams": [{"id" : "8","datapoints":[{"at":"2015-11-13T17:31:20.620426Z","value":"19.6"},{"at":"2015-11-13T17:30:21.078244Z","value":"19.6"}],}]
}]])
local response_body = {}
local response, status, header = http.request{
method = "PUT",
url = XivelyURL..XivelyID,
headers = {
["Content-Type"] = "application/json",
["Content-Length"] = string.len(json_data),
["X-ApiKey :"] = XivelyKey
},
source = ltn12.source.string(json_data),
sink = ltn12.sink.table(response_body)
}
response_body = table.concat(response_body)
print(response_body)
print(status)
print(header)
os.exit()
end
xap.init("dbzoo.lua.xivleyupdatetest","FF005D00" )
init()
xap.process()
The error message says: {"title":"Unauthorized","errors":"You do not have permission to access this resource"}
If it helps any I did a proof of concept Pachube posted quite some time ago (2yrs ago) much has probably changed since I had tha working.
http://www.homeautomationhub.com/content/pachube-applet