29.11.2022, 11:14
(29.11.2022, 11:01)admin Wrote: Try this query function:Now this is working great, but still sometimes are status update is immediate, but many times it is taking significant amount of time to update.
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