问题
Hi I am trying to sub and pub to mosquitto service runing on raspberry pi using Nodejs on my windows 10 but no thing happen on Rpi console here is my code
var mqtt = require('mqtt');
var client = mqtt.connect('mqtt://192.168.10.97');
client.on('connect', function () {
client.subscribe('presence');
client.publish('presence', 'Hello mqtt');
});
client.on('message', function (topic, message) {
// message is Buffer
console.log(message.toString());
client.end();
});
so my raspberry pi with ip 192.168.10.97 however when II test the commend from raspberry pi console it work secsussfully
mosquitto_sub -d -t "iot"
mosquitto_pub -d -t "iot" -m "Hi, This is my msg..."
so what is the problem ? thank you
来源:https://stackoverflow.com/questions/51076889/nodejs-to-mosquitto-raspberry-pi-pub-sub-not-work