29.11.2022, 11:01
Try this query function:
Code:
function query(req, out)
if not sock then
return
end
sock:send(req .. '\r\n')
local res, err = sock:receive()
if not res then
return close(err)
end
local pos = res:find('~')
if not pos then
return close('invalid reply1 ' .. res)
end
res = res:sub(pos)
if res:sub(2, #req) ~= req:sub(2) then
return close('invalid reply2 ' .. res)
end
local val = res:sub(#req + 2)
log('response', req, out, val)
val = tonumber(val)
if val then
grp.checkupdate(out, val)
end
end