Logic Machine Forum
Modbus Server logging writing IPs - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Modbus Server logging writing IPs (/showthread.php?tid=5041)



Modbus Server logging writing IPs - Christian_EWW - 19.10.2023

Hello.

On our LMs a Modbus TCP Server is running roughly based on https://openrb.com/lm-as-modbus-tcp-slave/
All works fine but at one customer something sporadically writes nonsens into our holding registers.
Is it possible to log the IP-address of the writing Client?
Adding a log(mb) to the function mbwriteregisters(register, value) does not gain the wanted result.

Thanks,
Christian


RE: Modbus Server logging writing IPs - admin - 19.10.2023

You should use this script: https://forum.logicmachine.net/showthread.php?tid=4288

Modify the handler function in the resident script to alert IP/port for each connection:
Code:
local function handler(sock)
  local ip, port = sock:getpeername()
  alert('modbus connection from: %s:%d', ip, port)

  copas.setErrorHandler(log)

  sock = copas.wrap(sock)
  sock:settimeout(60)

  while true do
    local res, err = mb.tcphandler(sock)
    if not res then
      break
    end
  end

  sock:close()
end



RE: Modbus Server logging writing IPs - Christian_EWW - 19.10.2023

Thanks for your support.
I will try the new version of the Modbus Server, but this will take some time.