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

86
Views
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 answers
Answer question

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