This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

Read with Wait function
I'm looking for a function which sends read request to KNX bus and waits for the result. The reason is I have two inputs which I need to be sure their values are actual.
This works but it's ugly because I don't check if the readings of both values were successful:'6/4/28')'6/4/45')


Is there such
LM5Lp, firmware: 2018.08.22, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151

Use this function:
function readresponse(alias, timeout)
  local obj, lb, ts, tu, delta, value
  obj = grp.find(alias)

  if not obj then
    return nil, 'object not found'

  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)
  ts, tu = os.microtime()

    delta = os.udifftime(ts, tu)
  until value ~= nil or delta >= timeout

  if value ~= nil then
    return value
    return nil, 'timeout'

res, err = readresponse('0/0/3')
log(res, err)
Excellent as usual Admin. Thank you.
But does lb:step() do yield? Isn't the cycle utilising the CPU to 100%?
LM5Lp, firmware: 2018.08.22, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151

It returns once a single local bus message has been received or timeout happens. Script does not consume CPU while waiting.

Forum Jump: