11.03.2020, 08:17
(11.03.2020, 06:59)admin Wrote: Try this resident script (sleep time = 0), change USER and PASS to your auth data. It will log all incoming data (log(line)). This is to check if there are any errors during communication. If everything is working then comment/delete this line.
Code:if not sock then
host = '192.168.100.211'
port = 80
path = '/bha-api/monitor.cgi?ring=doorbell,motionsensor&http-user=USER&http-password=PASS'
sock = require('socket').tcp()
sock:settimeout(10)
res, err = sock:connect(host, port)
if res then
sock:send(
'GET ' .. path .. ' HTTP/1.1\r\n' ..
'Host: ' .. host .. '\r\n\r\n'
)
else
alert('connect failed: ' .. tostring(err))
sock:close()
sock = nil
os.sleep(5)
end
end
line, err = sock:receive()
if line then
log(line)
if line:find('doorbell:') then
status = line:split(':')[2]
log('doorbell', line)
elseif line:find('motionsensor:') then
status = line:split(':')[2]
log('motionsensor', status)
end
else
alert('receive failed: ' .. tostring(err))
sock:close()
sock = nil
end
Thank You! It seems it does work, but it has a strange behaviour - I get the data fine, but I still get alert: "receive failed:timeout" - is this something I should worry about and check out or I could just comment the alert line and ignore it?