【发布时间】:2018-03-19 16:25:24
【问题描述】:
我正在尝试在设备孪生属性更改时在云后端接收通知。为此,我设置了一条路线,如下图链接所示
我还创建了一个 Azure 函数,该函数在默认使用者组上触发内置端点事件。但是,当我为其中一台设备更新设备孪生文档时,Azure 功能不会触发。如果我使用 iothubexplorer 或设备资源管理器监视设备的事件,我根本看不到“updateTwin”事件。但是,如果我从收到的设备发送常规设备到云端,它会起作用。
我使用以下代码更新设备孪生:
'use strict';
var Client = require('azure-iot-device').Client;
var Protocol = require('azure-iot-device-mqtt').Mqtt;
var connectionString = '';
var client = Client.fromConnectionString(connectionString, Protocol);
client.open(function(err) {
if (err) {
console.error('could not open IotHub client');
} else {
console.log('client opened');
client.getTwin(function(err, twin) {
if (err) {
console.error('could not get twin');
} else {
var body = {
temperature: '40'
}
console.log(twin.properties.reported);
twin.properties.reported.update(body, function(err) {
if (err) {
console.error('could not update twin');
} else {
console.log('twin state reported');
process.exit();
}
});
}
});
}
});
我也尝试使用 iothub-explorer 使用以下命令: iothub-explorer update-twin InitialDevice {\"properties\":{\"desired\": {\"interval\":9000}}} --login ""
【问题讨论】:
-
出于测试目的,您可以使用设备资源管理器(或 Azure 门户)更新设备孪生所需的属性,以在您的 Azure 函数中查看通知消息
标签: azure iot azure-eventhub azure-iot-hub azure-iot-sdk