-- Reader for a Schlumberger R5 gas meter using a CurrentCost digital development board and an HAH module(...,package.seeall) require ('xap') require('xap.bsc') info={ version="1.0", description="Gas Counter" } local Postinterval=5 local gastick=0 -- Incrementing ticker for 1cu of GAS local gas=0 -- Cumulative GAS reading local gasBSC function init() local f = xap.Filter() f:add("xap-header", "source", "dbzoo.livebox.CurrentCost:sensor.1") f:add("xap-header","class","xAPBSC.event") f:add("input.state","text","500") f:callback(function() gastick = gastick + 1 end) -- On Applet restart load last value gas = gasRead() xap.Timer(gasUpdate, Postinterval*60):start() -- Expose the current value as a BSC endpoint so we can push this to Pachube and monitor it. gasBSC = bsc.Endpoint{source="dbzoo.livebox.gas", direction=bsc.INPUT, type=bsc.STREAM} gasBSC:setText(tostring(gas)) end function gasRead() local file = io.open("/etc/plugboard/gascuft","r") gas = file:read("*all") file:close() return tonumber(gas) end function gasUpdate() gas = gas + gastick file = io.open("/etc/plugboard/gascuft","w+") file:write(tostring(gas)) file:close() gastick = 0 -- Update the BSC endpoint and send Event gasBSC:setText(tostring(gas)) gasBSC:sendEvent() end