Thingspeak & EmonCMS
Brett,
Would you consider adding support for Thingspeak - Its an opensource Xively alternative.
API Reference - https://uk.mathworks.com/help/thingspeak/api-reference.html
thanks
Gary,
I can give you some hellp. My free time at the moment is stil consumed with work.
Companies don't seem to realize that laying people off may reduce expenses however it does not reduce the work !
Thanks Brett, I'm sure you will be able to tidy my efforts up a bit when I'm done.
I now have a script uploading data to thing speak, will stress test it and post at weekend if all remains well.
thingspeak does look good, especially the ability to multi plot, etc.
I understand your work issues, I'm going through a bit of that myself. Who needs hobbies and play time anyhow :(
Garry
Thanks Brett, I'm sure you will be able to tidy my efforts up a bit when I'm done.
I now have a script uploading data to thing speak, will stress test it and post at weekend if all remains well.
thingspeak does look good, especially the ability to multi plot, etc.
I understand your work issues, I'm going through a bit of that myself. Who needs hobbies and play time anyhow :(
Garry
Sorry, posting from ipad so file is posted long hand in post - not attached.
please treat as beta and change API key before use. Also setup your fields in thing speak beforehand.
any probs/questions let me know!
attached is applet to upload to thing speak
garry
--[[
xAP Caching and Thingspeak interface
--]]
module(...,package.seeall)
require("xap")
require("pl.stringx").import()
require("pl.pretty")
socket = require("socket")
info={
version="1.0", description="xAP to Thingspeak applet"
}
local fields = {
{source = "dbzoo.RaspPi.Plugboard:HouseAveTemp",class = "xAPBSC.event",section = "input.state",value = "text"},
{source = "dbzoo.RaspPi.Controller:1wire.1",class = "xAPBSC.event",section = "input.state",value = "text"}
}
local APIKey = "xxxxxxxxxxxxxx"
local vfs = {
filter={},
data={}
}
for i,k in ipairs(fields) do
vfs.filter[i] = xap.Filter{["xap-header"] = {
source=fields[i]["source"],
class=fields[i]["class"] }}
end
function updateCache(frame)
for i,k in ipairs(fields) do
if frame:getValue("xap-header","source") == fields[i]["source"] then
vfs.data[i] = frame:getValue(fields[i]["section"],fields[i]["value"])
end
end
end
function send()
local host, port = "api.thingspeak.com", 80
client = socket.tcp()
client:connect(host, port)
local fieldtext = ""
for i,k in ipairs(fields) do
if vfs.data[i] then
fieldtext = fieldtext.."&field"..i.."="..vfs.data[i]
else end
end
client:send("GET /update?api_key="..APIKey..fieldtext
.. " HTTP/1.1\r\n"
.. "Host: api.thingspeak.com\r\n"
.. "Connection: close\r\n"
.. "Accept: */*\r\n"
.. "User-Agent: Mozilla/4.0 (compatible; Lua; Windows NT 5.1)\r\n"
.. "\r\n")
end
function init()
for _,k in pairs(vfs.filter) do
k:callback(updateCache)
end
xap.Timer(send, 60):start(false)
end
Not at all. Glad it was of some use.
I am using the lua script for reporting to Thingspeak, but it doesnt seem to work with on/off states from the pir sensor.I can find the code where it is converted for xively
int now = 0; | |
if(strcasecmp("on",value) == 0) { // Issue 27 | |
f = 1; | |
now = 1; // A boolean state should never be cached. | |
} else if(strcasecmp("off",value) == 0) { | |
f = 0; | |
now = 1;
|
But I don't know how to convert this to lua. Could an expert assist me?
I think you need an amendment to Gary's code to handle on/off (this code is untested)
function updateCache(frame)
for i,k in ipairs(fields) do
if frame:getValue("xap-header","source") == fields[i]["source"] then
vfs.data[i] = frame:getValue(fields[i]["section"],fields[i]["value"])
if vfs.data[i] == "on" then vfs.data[i] = 1 end
if vfs.data[i] == "off" then vfs.data[i] = 0 end
end
end
end
I have tried this but still not appearing. I can see the result coming through on xfx viewer and the message gets through to xively (https://personal.xively.com/feeds/2128585885 - feeds 7 and 8) but not on thingspeak (which I have made public for now https://thingspeak.com/channels/399026 - same feeds ). Attached is my applet with amendment.
In case it was a latching problem I tried changing both on and off to 1's and also tried changing 1 to "1" but neither works.
At the moment I am using ftp for the changes and just rebooting the machine. Maybe next I shall try stopping and starting the applet using ssh and see if I get any errors.
Unless anyone else has any bright idea? .....
Kim
Attachment | Size |
---|---|
Thingspeak2Applet.lua | 2.55 KB |
just after I posted I did a final check of what was ftp'd and it was the original file without amendment. So it DOES work exactly as posted by Brett.
So much for doing lots of checks before posting. Sorry.
Thanks for the modification Brett.
I only use it for charting temps so hadn't run into this issue.
Glad it's working for you Kim.
Garry
Andrew,
this should be doable with a plugboard script.
I am worried about the direction xively is heading too so I might have a crack at this myself when time allows.
I'll see if I can knock up a script at the weekend
Garry