03.07.2019, 08:18
Use this function:
Code:
function readresponse(alias, timeout)
local obj, lb, ts, tu, delta, value
obj = grp.find(alias)
if not obj then
return nil, 'object not found'
end
timeout = timeout or 3
lb = require('localbus').new(timeout / 10)
lb:sethandler('groupresponse', function(event)
if event.dst == obj.address then
value = busdatatype.decode(event.datahex, obj.datatype)
end
end)
grp.read(obj.address)
ts, tu = os.microtime()
repeat
lb:step()
delta = os.udifftime(ts, tu)
until value ~= nil or delta >= timeout
if value ~= nil then
return value
else
return nil, 'timeout'
end
end
res, err = readresponse('0/0/3')
log(res, err)