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.

TCP Socket Connection for Legrand
#26
Hi, I made several attempts to control the MX200 with a script, but unfortunately failed. I have the following commands on the line:

Code:
MH200
26.04.2022 19:53:58    
* string: *1*9*11##    90%
    
    
MH200
26.04.2022 19:54:15    
* string: *1*1000#0*11##    OK
    
    
MH200
26.04.2022 19:54:15    
* string: *1*0*11##    OFF

could you help me to bind them in a script so that I can recognize them on arrival and bind them to the respective objects and accordingly if the value of the object changes I send the command back to the gateway?
This is the code I use to get them in the log:
Code:
function read(sock)
  local buf = {}

  while true do
    local ch, err = sock:receive(1)

    if ch then
      local pr = buf[ #buf ]

      buf[ #buf + 1 ] = ch

      if ch == '#' and pr == '#' then
        break
      end

    else
      return nil, err
    end
  end

  local ret = table.concat(buf)
  log(ret)
  return ret
end




-- init socket
if not sock then
  require('socket')

  sock, err = socket.connect('192.168.1.247', 20000)

  -- set timeout to 1 second
  if sock then
    sock:settimeout(1)
  -- error opening connection, log error and wait before reconnecting 
  else
    error(err)
    sleep(5)
  end
end

-- socket handler
if sock then   

sock:send('*99*1##')

   res, err = read(sock)
 

  if data then
    log(data)
  end
end
Reply


Messages In This Thread
RE: TCP Socket Connection for Legrand - by a455115 - 14.06.2022, 06:45

Forum Jump: