Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

232
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda