我正在做一个基于物联网的项目。所以我需要连接 cloudmqtt
和 nodejs
服务器。
应用程序.js
// Create a MQTT Client
var mqtt = require('mqtt');
// Create a client connection to CloudMQTT for live data
var client = mqtt.connect('xxxxxxxxxxx', {
username: 'xxxxx',
password: 'xxxxxxx'
});
client.on('connect', function() { // When connected
console.log("Connected to CloudMQTT");
// Subscribe to the temperature
client.subscribe('Motion', function() {
// When a message arrives, do something with it
client.on('message', function(topic, message, packet) {
// ** Need to pass message out **
});
});
});
然后启动我的服务器。但是什么也没发生(没有错误消息,也没有警告)。请帮我解决这个问题?
原文由 Muhsin Keloth 发布,翻译遵循 CC BY-SA 4.0 许可协议
现在
cloudmqtt
和nodejs
服务器通过提供额外的参数连接,如 clientId、keepalive、protocolVersion 等。应用程序.js