Skip to content Skip to sidebar Skip to footer

Can't Connect To Localhost Mosquitto Broker With Javascript?

I have a raspberry pi with a Mosquitto Broker running on it connected to a sensor module with MQTT Protocol inbuilt. If I use this code in terminal, I can subscribe and see my data

Solution 1:

As I said in the comments by default mosquitto does not configure a MQTT over WebSockets listener by default.

The Paho MQTT JavaScript client can only connect to a broker via MQTT over WebSockets.

To add a MQTT over WebSockets you need to add the following to the mosquitto.conf file (or to a file in /etc/mosquitto/conf.d)

listener 8083protocolwebsockets

You would then need to make sure the client is connecting to port 8083

Post a Comment for "Can't Connect To Localhost Mosquitto Broker With Javascript?"