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.

Logger All Datagrams KNX BUS to mysql
#1
Hello I have a project in which I need to save in a bbdd mysql all the states of all KNX groups in real time.

In other words, I need to listen to the KNX BUS and send all the datagrams that are written to the BUS to a mysql DB.

Can LM do this?

Can somebody help me?.

Thank you.
Reply
#2
See this thread on a basic example of bus monitoring. It can be easily extended to send data to mysql or any other database:
https://forum.logicmachine.net/showthread.php?tid=273
Reply
#3
Maybe an idea would be, to mark all the objects with "LOG" and every hour, to synchronize the objects of the LM bbdd with the DB of mysql?
Reply
#4
You can modify CSV example to export to mysql: https://openrb.com/example-export-last-h...-from-lm2/
Reply
#5
This is my code, maybe not perfect but it works

Code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
--[[ * table: [datalen]   * number: 4 [datahex]   * string: 453FE000 [data]   * number: 3070 [srcraw]   * number: 8448 [dstraw]   * number: 17930 [type]   * string: groupwrite [src]   * string: 2.1.0 [dst]   * string: 8/6/10 --]] if not client then   require('genohm-scada.eibdgm')   objects = grp.all()   datatypes = {}   for _, object in ipairs(objects) do     datatypes[ object.id ] = {object.name, object.datatype}   end     function writemysql(I_datalen,I_datahex,I_data,I_srcraw,I_dstraw,I_type,I_src,I_dst,I_name)       require('luasql.mysql')     env = luasql.mysql()     dbcon = env:connect('xxxxxxxxx', 'xxxxxxx', 'xxxxxxxx', '192.168.12.25', '3306')     if dbcon then       if I_type == 'groupread' then         cursor = dbcon:execute( 'insert into datalog (datetime,datalen,srcraw,dstraw,type,src,dst,dstname) values (now(),'..I_datalen..','..I_srcraw..','..I_dstraw..',"'..I_type..'","'..I_src..'","'..I_dst..'","'..I_name..'") ' )       else           cursor = dbcon:execute( 'insert into datalog (datetime,datalen,datahex,data,srcraw,dstraw,type,src,dst,dstname) values (now(),'..I_datalen..',"'..I_datahex..'",'..tostring(I_data)..','..I_srcraw..','..I_dstraw..',"'..I_type..'","'..I_src..'","'..I_dst..'","'..I_name..'") ' )        end       --log(cursor)       dbcon:close()       env:close()     end   end     function writehandler(event)     if datatypes[ event.dstraw ] then       name = datatypes[ event.dstraw ][1]         dpt = datatypes[ event.dstraw ][2]     else       name = ''     end     if dpt then       event.data = knxdatatype.decode(event.datahex, dpt)     else         event.data = nil      end     --log(event)     writemysql(event.datalen,event.datahex,event.data,event.srcraw,event.dstraw,event.type,event.src,event.dst,name)   end   function readhandler(event)     if datatypes[ event.dstraw ] then         name = datatypes[ event.dstraw ][1]     else       name = ''     end     --log(event)     writemysql(event.datalen,event.datahex,'',event.srcraw,event.dstraw,event.type,event.src,event.dst,name)   end   -- knx connection   client = eibdgm:new({ timeout = 1 })   client:sethandler('groupwrite', writehandler)   client:sethandler('groupresponse', writehandler)   client:sethandler('groupread', readhandler) end -- handle knx client:step()
Reply


Forum Jump: