Reputation: 2534
I want to build a web page to send and receive topics. I'm using mosquitto and MQTT.js.
protocol websockets
listener 1884
sudo mosquitto -c /etc/mosquitto/mosquitto.conf
and get
1647529861: mosquitto version 2.0.14 starting
1647529861: Config loaded from /etc/mosquitto/mosquitto.conf.
1647529861: Opening websockets listen socket on port 1884.
1647529861: mosquitto version 2.0.14 running
mqtt.html
(full source):
<script src="https://unpkg.com/mqtt/dist/mqtt.min.js"></script>
<script>
const client = mqtt.connect("ws://localhost:1884")
</script>
Problem:
00000000: 2002 0005
. When I check the log of mosquitto: I get a lot of 1647530429: Client mqttjs_b0e54ea4 closed its connection.
I'm running on:
LSB Version: n/a
Distributor ID: ManjaroLinux
Description: Manjaro Linux
Release: 21.2.5
Codename: Qonos
Upvotes: 1
Views: 1151
Reputation: 59608
You need to add allow_annonymous true
to your config file.
The default for mosquitto 2.x is to not allow connections from unauthenticated clients.
You should also reverse the lines in your config,
The protocol
option only applies to the last listener
in order down the file.
What you have will apply the websocket protocol to the default listener on port 1883.
allow_anonymous true
listener 1884
protocol websockets
Upvotes: 5