Thingspeak & EmonCMS

9 replies [Last post]
AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012

Brett,

Would you consider adding support for Thingspeak - Its an opensource Xively alternative.

https://thingspeak.com/

API Reference - https://uk.mathworks.com/help/thingspeak/api-reference.html

thanks

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Andrew,this should be doable

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 

AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012
Hi Garry,That sounds like a

Hi Garry,

That sounds like a plan

Thanks

Andeew

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Gary,I can give you some

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 !

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Thanks Brett, I'm sure you

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

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Thanks Brett, I'm sure you

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

garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Sorry, posting from ipad so

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

 

AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012
Excellent work Garry :)my

Excellent work Garry :)

my quick test feed for the 1Wires - https://thingspeak.com/channels/87676

I had to create the channels / fields first to access an additional API key for writing to the channel but after this the feed data appeared

thanks

Andrew

 

AndrewJ
Offline
United Kingdom
Joined: 22 Nov 2012
Garry,I hope you dont mind, I

Garry,

I hope you dont mind, I made a few modifications to your script to allow it to be used with OpenEnergyMonitors EmonCMS http://www.emoncms.org

Emoncms contains some very nice built in apps for historical power logging plus a matching android app.

As above set you own API key / Endpoints / Update timer.

Thanks

Andrew

AttachmentSize
emoncmsApplet.lua 2.4 KB
garrydwilms
Offline
United Kingdom
Joined: 31 Mar 2011
Not at all. Glad it was of

Not at all. Glad it was of some use. 

Hardware Info