11.05.2020, 06:52
You need to modify the upgrade_request function in websocket library:
Then create connection like this (change API key):
Code:
local upgrade_request = function(req, key)
local format = string.format
local lines = {
format('GET %s HTTP/1.1',req.path or ''),
format('Host: %s',req.host),
'Upgrade: websocket',
'Connection: Upgrade',
format('Sec-WebSocket-Key: %s',key),
'Sec-WebSocket-Version: 13',
}
if self.protocol then
tinsert(lines, format('Sec-WebSocket-Protocol: %s', self.protocol))
end
if req.port and req.port ~= 80 then
lines[2] = format('Host: %s:%d',req.host,req.port)
end
if req.userinfo then
local auth = format('Authorization: Basic %s', base64enc(req.userinfo))
tinsert(lines, auth)
end
tinsert(lines,'\r\n')
return tconcat(lines,'\r\n')
end
Then create connection like this (change API key):
Code:
ws = require('user.websocket')
json = require('json')
url = 'wss://door.casambi.com/v1/bridge/'
client, err = ws.client('sync', 10)
client.protocol = 'API-key'
res, err = client:connect(url)
log(res, err)