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
#25
Okay, I get it.

I used the sample TCP code:
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##')
 
 
 
--data = sock:receive(14)
   res, err = read(sock)
 
 
 
--sock:send('*#1*12##')
-- log('check')
-- sock:send('*1*1*12##')
  -- got data, log it
  if data then
    log(data)
  end
end

 and I'm currently getting this:
* # 4 * 1 * 0 * 0229 ## in log.
Which means that the temperature of thermostat 1 is 22.9 degrees. How to separate the digit with the code 1 to be address 32/1/1 and write the value 22.9 in it? How do I separate receiving and sending commands so that it works properly?
Reply


Messages In This Thread
RE: TCP Socket Connection for Legrand - by a455115 - 26.04.2022, 13:52

Forum Jump: