0

This is the first time I'm working with mqtt, be kind :)

Sometimes, the MQTT connection connects, receives a few messages, goes offline and reconnects again and again. The cycle takes about 5 seconds. This is the logs that I get in the console:

MQTT Connect
MQTT Message from Channel
MQTT Offline
MQTT Reconnecting
MQTT Connect
MQTT Offline
MQTT Reconnecting

It never stops. I also get a lot of 101 http requests every second:

Request URL: wss://myserver:8083/
Request Method: GET
Status Code: 101 Switching Protocols
---
Response headers:
Connection: Upgrade
Sec-WebSocket-Accept: 8MLdWBXF8YJ919JhE98mxM4R8IA=
Sec-WebSocket-Protocol: mqtt
Upgrade: WebSocket

I'm using the MQTT.js mqtt client with these options:

{
  keepalive: 10
  username: "OOsj6Q0kX3xTVCfLi6QA"
  password: "NKRsJYfD3ulms9s43Qho"
  clientId: "2906890"
  reconnectPeriod: 1000
  connectTimeout: 30000
  port: 8083
  protocol: "wss"
  hostname: "myserver"
}

The MQTT.js docs are not very beginner friendly and I'm struggling to understand the problem. Any idea what could be the problem?

  • Why I get a lot of 101 http requests? What does it mean?

  • Why it goes offline again and again? Under what conditions the connection goes offline? Bad internet connection?

Arman
  • 720
  • 2
  • 7
  • 18

1 Answers1

-1

The MQTT broker you are using is telling you that it doesn't want to use 'wss' as the protocol, it wants 'mqtt' -- that is why you are getting the 101 errors.

As to the disconnects, it's hard to know without seeing your client code. I would guess that since you are using WSS instead of MQTT the connection is timing out or just not configured correctly. Try switching your client to use 'mqtt' if you can and see what happens.

JD Allen
  • 799
  • 5
  • 12