Skip to content
Advertisement

Mosquitto and simple Paho JS Client

I am trying to get a simple mqtt broker set up and access it from a web page. I have had pretty much 0 luck.

I’ve got mosquitto 2.0.14 downloaded and running. Here’s my configuration file:

JavaScript

This generates the following log when I run mosquitto -c mosquitto_conf -v

JavaScript

Here’s my html file, which I simply open in the browser. It uses Paho’s js client.:

JavaScript

I’m using a guide from this website: http://www.steves-internet-guide.com/using-javascript-mqtt-client-websockets/

It errors out with the following console error in the browser:

JavaScript

I have been having a hard time finding an updated tutorial that works. My ultimate goal is to create a react app that connects to an mqtt broker via websockets and receives messages to update state in redux.

Questions: How do I get the js client to connect? How do I set the host for mosquitto? Can I use a diff host like myhost.local or am I stuck using 127.0.0.1 or whatever I see when I run ipconfig (I’m on windows)?

Advertisement

Answer

You need to add allow_anonymous true to allow users to connect without supplying a username/password.

This is part of the set of changes introduced in v2.0 to improve the default security posture of mosquitto out of the box.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement