nodejs to mosquitto raspberry pi pub sub not work

你说的曾经没有我的故事 提交于 2019-12-11 06:05:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!