Okay, I get it.
I used the sample TCP code:
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?
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?