11.05.2021, 07:08
1. Install 2021 RC1 firmware.
4. Create a resident script with 0 sleep time.
This example is only a starting point, it should be extended with additional send/receive logic.
2. Create a user library named websocket using the attached source.
3. Upload certificates via FTP using ftp login, rename files with long names to cert.pem and key.pem accordingly.4. Create a resident script with 0 sleep time.
Code:
if not client then
require('json')
ws = require('websocket')
url = 'wss://test-hub.usbim.com'
client, err = ws.client('sync', 1)
opts = {
protocol = 'tlsv13',
key = '/home/ftp/key.pem',
password = [[*q&'wrKQsx+#bj8pbEV=%7Gpr"S+sxV2ngr`N}SjCC`X#rtt!wY6PL`d2'3!^x}u]],
certificate = '/home/ftp/cert.pem',
cafile = '/home/ftp/ca-chain.cert.pem',
}
res, err = client:connect(url, opts)
if not res then
log('connection failed', err)
client:sock_close()
client = nil
end
end
if client then
frame, opcode, clean, code, reason = client:receive()
log(frame, opcode, clean, code, reason)
if frame then
data = json.pcdecode(frame)
log(data)
elseif reason ~= 'timeout' then
log('connection dropped', reason)
client:sock_close()
client = nil
end
end
This example is only a starting point, it should be extended with additional send/receive logic.