我已经创建了一个模块来接收云到设备的消息,但是在该模块上没有收到消息,我是否缺少任何编码?
var Transport = require('azure-iot-device-mqtt').Mqtt;
var Client = require('azure-iot-device').ModuleClient;
Client.fromEnvironment(Transport, function (err, client) {
if (err) {
throw err;
} else {
client.on('error', function (err) {
throw err;
});
// connect to the Edge instance
client.open(function (err) {
if (err) {
throw err;
} else {
console.log('IoT Hub module client initialized');
client.on('message', function (msg) {
client.complete(msg, printResultFor('Receiving message'));
var message = msg.getBytes().toString('utf8');
console.log('----');
console.log(message);
console.log('----');
var outputMsg = new Message(message);
client.sendOutputEvent('output1', outputMsg, printResultFor('Sending received message'));
});
client.on('error', function (err) {
console.error(err.message);
});
console.log('now listening for C2D messages...');
}
});
}
});
监视器
[C2DMessageMonitor]收到的消息:“ [{\” machine \“:{\” temperature \“:40.750164436176497,\” pressure \“:1.0854617712099808},\” ambient \“:{\” temperature \“:40.450729128416036 ,\“湿度\”:26},\“ timeCreated \”:\“ 2018-08-06T13:28:52.0375008Z \”}]“
[C2DMessageMonitor]状态:MessageCompleted
答案 0 :(得分:1)
C2D消息。在建立支持的同时,它可能适用于某些协议,但目前尚未进行任何验证。