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.

Local bus and sending to MQtt
#1
im running the below in script to port all obj wit tag with prefix 'MQ' to mqtt it runs everytime local bus has a message, 
is there a simple way to make it more efficent? is there a better way to do this?  at the moment i have one resident script with a loop which manages local bus and mqtt in one place.

Code:
function localbus_onmessage(event)

event_get_tags = grp.gettags(event.dst)
  -- check if tag has MQ prefix
    for _, tag in ipairs(event_get_tags) do
    tag_is_MQ = tag:match('MQ (.*)')
 
  if tag_is_MQ then
      -- get data type for knx obj
      event_get_obj = grp.find(event.dst)
    --decode data
     tx_payload = busdatatype.decode(event.datahex, event_get_obj.datatype, event.dstraw)
  --  log(event.dst, tx_payload)
 
    if type(tx_payload) == 'boolean' then   
        tx_payload = tx_payload and 1 or 0
     end
      -- extract control type from obj name
      cntrl_typ = string.split(event_get_obj.name, ' ')
     
--log(tx_payload)
   mqtt_send:publish('from_knx_tag/'..  tag_is_MQ, cntrl_typ[1] ..' '.. tx_payload)
     
    break
  end
end       
Reply


Messages In This Thread
Local bus and sending to MQtt - by benanderson_475 - 03.01.2024, 01:48
RE: Local bus and sending to MQtt - by admin - 03.01.2024, 07:31
RE: Local bus and sending to MQtt - by admin - 03.01.2024, 10:57
RE: Local bus and sending to MQtt - by admin - 03.01.2024, 11:13

Forum Jump: