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.

BIM ioT
#13
1. Create a user library named bim-iot using the attached source.
2. Make sure that the updated websocket library and keys are in place.
3. Create a resident script with sleep time = 0:
Code:
if not wsclient then
  require('json')
  require('user.bim-iot')

  url = 'wss://test-hub.usbim.com'
  wsclient = require('user.websocket').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 = wsclient:connect(url, opts)
  if res then
    log('WS connection OK')
  else
    log('WS connection failed', err)
    wsclient:sock_close()
    wsclient = nil
  end

  if not lb then
    lb = require('localbus').new()

    lb:sethandler('groupwrite', eventhandler)
    lb:sethandler('groupresponse', eventhandler)

    lbfd = lb:getfd()
  end

  wsfd = wsclient.sock:getfd()

  init()
  sendall()
end

if wsclient then
  local res, lbstat, wsstat = socket.xselect(10, lbfd, wsfd)

  if res > 0 then
    if lbstat then
      lb:step()
    end

    if wsstat then
      local msg, opcode, clean, code, reason = wsclient:receive()
      log(msg, opcode, clean, code, reason)

      if msg then
        onwsmessage(msg)
      elseif reason ~= 'timeout' then
        log('WS connection dropped', reason)
        wsclient:sock_close()
        wsclient = nil
      end
    end
  end
else
  -- handle incoming object messages before trying to reconnect WS
  lb:loop(10)
end
Since I don't have the tools to test some parts might not work.

Attached Files
.lua   bim-iot.lua (Size: 2.85 KB / Downloads: 14)
Reply


Messages In This Thread
BIM ioT - by gdimaria - 06.05.2021, 15:05
RE: BIM ioT - by admin - 06.05.2021, 15:08
RE: BIM ioT - by gdimaria - 07.05.2021, 07:54
RE: BIM ioT - by gdimaria - 06.05.2021, 15:11
RE: BIM ioT - by admin - 07.05.2021, 07:59
RE: BIM ioT - by gdimaria - 10.05.2021, 16:16
RE: BIM ioT - by admin - 11.05.2021, 07:08
RE: BIM ioT - by gdimaria - 11.05.2021, 09:30
RE: BIM ioT - by admin - 11.05.2021, 09:32
RE: BIM ioT - by gdimaria - 11.05.2021, 09:41
RE: BIM ioT - by admin - 11.05.2021, 09:42
RE: BIM ioT - by gdimaria - 11.05.2021, 10:24
RE: BIM ioT - by admin - 13.05.2021, 06:23
RE: BIM ioT - by gdimaria - 13.05.2021, 09:05
RE: BIM ioT - by admin - 13.05.2021, 09:06
RE: BIM ioT - by gdimaria - 13.05.2021, 09:51
RE: BIM ioT - by admin - 13.05.2021, 09:53
RE: BIM ioT - by gdimaria - 13.05.2021, 10:01
RE: BIM ioT - by gdimaria - 28.05.2021, 11:07
RE: BIM ioT - by admin - 28.05.2021, 13:57
RE: BIM ioT - by gdimaria - 06.06.2021, 16:35
RE: BIM ioT - by admin - 07.06.2021, 09:59
RE: BIM ioT - by gdimaria - 09.06.2021, 15:17
RE: BIM ioT - by admin - 10.06.2021, 06:05
RE: BIM ioT - by gdimaria - 10.06.2021, 07:48
RE: BIM ioT - by admin - 10.06.2021, 07:53
RE: BIM ioT - by gdimaria - 10.06.2021, 08:26
RE: BIM ioT - by gdimaria - 10.06.2021, 09:27
RE: BIM ioT - by admin - 10.06.2021, 10:03
RE: BIM ioT - by gdimaria - 10.06.2021, 17:34

Forum Jump: