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 that you accept these cookies being set.

localbus
#1
hi , i am trying to work with localbus but i don't receive any logs from the groupcallback  function, i want to monitor several obj in a resident script.
in the attached i can see the handlers table but also udp{unconnected} maybe this is my problem ??

Code:
lb = require('localbus').new()

lb:sethandler('groupwrite', groupcallback)
lb:sethandler('groupread', groupcallback)
lb:sethandler('groupresponse', groupcallback)

log(lb)

function groupcallback(event) 
 
  log(event)
 
  if event.dst == '0/2/1' then   
    local value = knxdatatype.decode(event.datahex, dt.uint16)   
    log(value)
   
  end
end
many thanks
Reply
#2
Hi!
Does script engine gives you any errors?

Check that on error log...
Reply
#3
You need to call step for it to receive data. You should also define callback before setting it.
Code:
if not lb then
  lb = require('localbus').new(1)

  function groupcallback(event)  
    log(event)
    
    if event.dst == '0/2/1' then    
      local value = knxdatatype.decode(event.datahex, dt.uint16)    
      log(value)
    end
  end

  lb:sethandler('groupwrite', groupcallback)
  lb:sethandler('groupread', groupcallback)
  lb:sethandler('groupresponse', groupcallback)
end

lb:step()
Reply
#4
(31.07.2020, 08:35)admin Wrote: You need to call step for it to receive data. You should also define callback before setting it.
Code:
if not lb then
  lb = require('localbus').new(1)

  function groupcallback(event) 
    log(event)
   
    if event.dst == '0/2/1' then   
      local value = knxdatatype.decode(event.datahex, dt.uint16)   
      log(value)
    end
  end

  lb:sethandler('groupwrite', groupcallback)
  lb:sethandler('groupread', groupcallback)
  lb:sethandler('groupresponse', groupcallback)
end

lb:step()
Many Thanks Smile
Reply
#5
(31.07.2020, 08:35)admin Wrote: You need to call step for it to receive data. You should also define callback before setting it.
Code:
if not lb then
  lb = require('localbus').new(1)

  function groupcallback(event) 
    log(event)
   
    if event.dst == '0/2/1' then   
      local value = knxdatatype.decode(event.datahex, dt.uint16)   
      log(value)
    end
  end

  lb:sethandler('groupwrite', groupcallback)
  lb:sethandler('groupread', groupcallback)
  lb:sethandler('groupresponse', groupcallback)
end

lb:step()
Hello Admin,
can I ask you for documentation for localbus library?

We are confusing what happens with queue if is too long?
Can get somehow batch of e.g. ten telegrams in one step?
Can we filter somehow range of group addresess to listen?
What is return value of lb.step?

Thanks a lot!
Reply
#6
There's no documentation because localbus is not needed for most users.

Quote:We are confusing what happens with queue if is too long?
If the queue is too long then new message will be dropped.

Quote:Can get somehow batch of e.g. ten telegrams in one step?
You can use lb:loop(timeout) to loop for a certain time. For this to work correctly you should set default timeout to a smaller value when creating localbus socket via new(timeout).

Quote:Can we filter somehow range of group addresess to listen?
Localbus will receive all messages anyway so you need to filter groups manually in callback functions.

Quote:What is return value of lb.step?
step return true when any message was received or nil, error on timeout.

If you want to correctly communicate with multiple sockets/timers the easiest way is to use copas.
Here's how to wrap localbus socket into copas context:
Code:
copas.addserver(lb.sock, function()
  lb.sock = copas.wrap(lb.sock)
  while true do
    lb:step()
  end
end, 1)
Reply


Forum Jump: