This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Creation of custom package
#15
(11.05.2020, 06:52)admin Wrote: You need to modify the upgrade_request function in websocket library:
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)

After making the changes in library, it throws the following error:-

User library websocket:292: attempt to index global 'self' (a nil value)
stack traceback:
User library websocket:292: in function 'upgrade_request'
User library websocket:462: in function 'connect'
User script:8: in main chunk
Reply


Messages In This Thread
Creation of custom package - by Bitver - 17.03.2018, 10:03
RE: Creation of custom package - by admin - 19.03.2018, 07:33
RE: Creation of custom package - by admin - 20.03.2018, 14:27
RE: Creation of custom package - by Alexander - 19.05.2021, 19:12
RE: Creation of custom package - by rocfusion - 20.03.2018, 18:53
RE: Creation of custom package - by rocfusion - 23.03.2018, 02:30
RE: Creation of custom package - by rocfusion - 23.03.2018, 06:04
RE: Creation of custom package - by admin - 23.03.2018, 11:30
RE: Creation of custom package - by rocfusion - 23.03.2018, 14:25
RE: Creation of custom package - by admin - 23.03.2018, 14:41
RE: Creation of custom package - by rocfusion - 26.03.2018, 08:42
RE: Creation of custom package - by nickd - 03.03.2019, 09:30
RE: Creation of custom package - by admin - 26.03.2018, 08:48
RE: Creation of custom package - by doshibn - 09.05.2020, 12:10
RE: Creation of custom package - by admin - 11.05.2020, 06:52
RE: Creation of custom package - by saumya_gandhi@outlook.com - 11.05.2020, 11:19
RE: Creation of custom package - by admin - 11.05.2020, 11:24
RE: Creation of custom package - by admin - 20.05.2021, 05:27
RE: Creation of custom package - by myg - 05.05.2023, 21:26
RE: Creation of custom package - by admin - 08.05.2023, 09:02
RE: Creation of custom package - by admin - 11.12.2023, 12:47

Forum Jump: