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

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

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 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