02.02.2022, 18:51
(02.02.2022, 15:53)admin Wrote: You can adapt this code for your use case: https://forum.logicmachine.net/showthrea...1#pid15941
Add headers to initial request lines and change APPKEY to the actual application key:
Code:sock:send(
'GET ' .. path .. ' HTTP/1.1\r\n' ..
'Host: ' .. host .. '\r\n' ..
'Accept: text/event-stream\r\n' ..
'hue-application-key: APPKEY\r\n' ..
'\r\n'
)
i think i do something wrong because the output of the lines is the same as the bridge html source what i see in the browser
Code:
if not sock then
host = 'my bridge ip'
port = 80
path = '/eventstream/clip/v2'
appkey = 'mysecretappkey'
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' ..
'Accept: text/event-stream\r\n' ..
'hue-application-key: ' .. appkey .. '\r\n' ..
'\r\n'
)
else
log('connect failed: ' .. tostring(err))
sock:close()
end
end
line, err = sock:receive()
if line then
log('line: ' .. line)
else
log('receive failed: ' .. tostring(err))
sock:close()
sock = nil
end