Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

231
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda