module("bluenode", package.seeall) require("xap.bsc") jeenode = require("xap.jeenode") Nodule = jeenode.Nodule class = require("pl.class") require("pl") class.BlueNode(Nodule) local timestamp={os.time(),os.time()} local userstate={} local useraddress={ ":80EA:96:9", ":23:23:23:" } local timeout = 300 -- create BSC endpoints function BlueNode:build(...) Nodule.build(self, ...) self:add {key="user1", direction=bsc.INPUT, type=bsc.BINARY} self:add {key="user2", direction=bsc.INPUT, type=bsc.BINARY} end function expirycheck() local now = os.time() for i = 1, 2 do local DiffTime = now - timestamp[i] if DiffTime > timeout then userstate[i]=0 end end end function BlueNode:process(data) --[[ -- From the bluenode.pde Sketch struct { char[10] BTdata; } payload; --]] local char1,char2,char3,char4,char5,char6,char7,char8,char9,char10= jeenode.bitslicer(data,8,8,8,8,8,8,8,8,8,8) local address=string.format("%c%c%c%c%c%c%c%c%c%c", char1,char2,char3,char4,char5,char6,char7,char8,char9,char10) for i = 1,2 do if address == useraddress[i] then userstate[i] = 1 timestamp[i] = os.time() end expirycheck() end -- The keys here must match the key values from the self:add{key=x} Nodule.process(self,{user1=userstate[1],user2=userstate[2]}) end