14.06.2022, 06:45
Hi, I made several attempts to control the MX200 with a script, but unfortunately failed. I have the following commands on the line:
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:
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