They removed support for node.js with v3. So I connected to mqtt server with node.js using mqtt library. But I am not able to pull the sensor data. I’m wondering if anyone has used the mqtt library before. You can see my mqtt connection code below. I would be very grateful if you could edit it and post it as an answer.
const mqtt = require("mqtt");
const connectUrl = `mqtt://my_url:1883`;
const client = mqtt.connect(connectUrl, {
clean: true,
connectTimeout: 4000,
username: "username",
password:
"password",
reconnectPeriod: 1000,
});
const topic = "topic_name";
client.on("connect", () => {
console.log("Connected");
client.subscribe([topic], () => {
console.log(`Subscribe to topic '${topic}'`);
});
});
client.on("message", (topic, payload) => {
console.log("Received Message:", topic, payload.toString());
});```