-- Captures data from electric meter module(...,package.seeall) require ('xap') require('xap.bsc') info={ version="1.0", description="Electric meter totaliser" } --meter sends rf package every 5 ticks and 1000 ticks = 1 Kilowatt local TotalElectric=0 -- Cumulative meter reading local TotalElectricBSC function leccyRead() local file = io.open("/etc/plugboard/PortLeccy","r") TotalElectric = file:read("*all") file:close() return tonumber(TotalElectric) end function leccyUpdate(frame) local ECount =frame:getValue("input.state","text") --print("test") --print(ECount) TotalElectric = tonumber(TotalElectric) + tonumber(ECount) file = io.open("/etc/plugboard/PortLeccy","w+") file:write(tostring(TotalElectric)) file:close() -- Update the BSC endpoint and send Event TotalElectricBSC:setText(TotalElectric) TotalElectricBSC:setText(tostring(ECount)) TotalElectricBSC:sendEvent() end function init() local f = xap.Filter() -- f:add("xap-header", "source", "dbzoo.livebox.jeenode:leccy.watts") f:add("xap-header","source", "dbzoo.livebox.Controller:1wire.1") f:add("xap-header","class","xAPBSC.event") -- f:add("command","text",xap.FILTER_ANY) f:callback(leccyUpdate) -- On Applet restart load last value TotalElectric = leccyRead() -- Expose the current value as a BSC endpoint so we can push this to Pachube and monitor it. TotalElectricBSC = bsc.Endpoint{source="dbzoo.livebox.jeenode:leccy.total", direction=bsc.OUTPUT, type=bsc.STREAM} TotalElectricBSC:setText(tostring(TotalElectric)) end