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

85
Visualizações
Mqtt.js how to handle multiple topics

I'm using multiple ESP8266 to monitor multiple rooms around my house. And I was wondering what is the best way to handle the incoming data if for each room I'm waiting for a specific temperature level to turn on the AC or Heater.

Do I handle all the data and the turning off and on the AC/Heater in a global .on message method or do I create for each room a .on message? I'm using MQTT.js (https://www.npmjs.com/package/mqtt)

this.client.on("message", (topic, message) => {
  console.log(`Received ${message}`);
  const roomId = JSON.parse(message);
  this.onReceiveMessage(topic, message);
});

Thank you

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There will only ever be one event when a message is delivered to the client, if you add more than one on message event listener they will all be called with the same topic and message values for a given message.

So there is no value in registering more than 1 on message client, you should then filter on the supplied topic, how you then choose to organise the code is entirely up to you and what actions you wish to take.

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