Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
Try to connect to Mosquitto MQTT over WebSockets with Mqtt.js

I want to build a web page to send and receive topics. I'm using mosquitto and MQTT.js.

  1. I'm using this as an config file:
    protocol websockets
    listener 1884
    
  2. I run 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
    
  3. I'm using a simple 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:

  • In Chrome it just connects with 101 and does it again and again. When you check the websockets messages, the "server" receives: 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
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!