03.02.2022, 10:12
(This post was last modified: 03.02.2022, 10:44 by gjniewenhuijse.)
(03.02.2022, 09:50)admin Wrote: Does it work for you with curl? HTTPS is 443 but some extra code is needed for the raw socket to use encryption: https://forum.logicmachine.net/showthrea...903#pid903
yep, curl for windows code works:
curl --insecure -N -H "hue-application-key: sameapiuserasbefore" -H "Accept: text/event-stream" https://myipaddress/eventstream/clip/v2
and thx, the raw socket example works also.
working code for evenstream
Code:
if not sock then
host = 'fillyourip'
port = 443
proto = 'tlsv12'
path = '/eventstream/clip/v2'
appkey = 'fillyouruser'
require('ssl')
sock = require('socket').tcp()
sock:settimeout(10)
res, err = sock:connect(host, port)
if res then
sock = ssl.wrap(sock, proto)
res, err = sock:dohandshake()
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('handshake failed: ' .. tostring(err))
end
else
log('connect failed: ' .. tostring(err))
sock:close()
end
end
line, err = sock:receive()
if line then
--log('line: ' .. line)
if line:find(': hi') then
log('connection ok: ', line)
elseif line:find('data:') then
--status = line:split(':')[2]
log('data', line)
end
else
log('receive failed: ' .. tostring(err))
sock:close()
sock = nil
end