gassy person
gassy person

Reputation: 11

Unable to connect to mosquitto broker server in mqtt-react

I am using a mosquitto for my broker server, when I use mqtt-react and put my internet's local ip address I get this error in the console:

WebSocket connection to 'ws://192.XXX.X.X:1883/' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET

and in my terminal where mosquitto is opened, it says this

Client <unknown> disconnected due to protocol error.

Any ideas appreciated

Upvotes: 1

Views: 3401

Answers (1)

hardillb
hardillb

Reputation: 59638

MQTT react is trying to use MQTT over Websockets to connect to the broker, this is because it is based in a web browser so the sandbox will only allow HTTP or Websocket connections

By default Mosquitto only starts one listener (on port 1883) which only supports MQTT over TCP. If you want to connect with MQTT over Websockets you will need to add a new listener on a new port. To do this add the following to your mosquitto.conf file:

listener 8083
protocol websockets

You will need to update the URL in your code for the broker to be as follows:

ws://192.XXX.X.X:8083

Upvotes: 2

Related Questions