module("oilnode", package.seeall) require("xap.bsc") jeenode = require("xap.jeenode") Nodule = jeenode.Nodule class = require("pl.class") class.OilNode(Nodule) -- create BSC endpoints function OilNode:build(...) Nodule.build(self, ...) -- Creates the endpoints: self[key] as in self.light, self.moved etc.. -- If the user has configured that they want them that is. self:add {key="oil", direction=bsc.INPUT, type=bsc.STREAM} self:add {key="moved", direction=bsc.INPUT, type=bsc.BINARY} self:add {key="humi", direction=bsc.INPUT, type=bsc.STREAM} self:add {key="temp", direction=bsc.INPUT, type=bsc.STREAM} self:add {key="battery", direction=bsc.INPUT, type=bsc.STREAM} end function OilNode:process(data) -- local li, mo, hu, te, lo = jeenode.bitslicer(data,8,1,7,-10,1) local oi, mo, hu, te, ba = jeenode.bitslicer(data,16,1,7,-10,16) te = te / 10 ba = ba/100 oi=math.floor(oi/(1+(.0008*te)))-11 -- The keys here must match the key values from the self:add{key=x} Nodule.process(self,{oil=oi,moved=mo,humi=hu,temp=te,battery=ba}) end