【问题标题】:Azure IoT Hub Device Twin Change Notification IssuesAzure IoT 中心设备孪生更改通知问题
【发布时间】:2018-03-19 16:25:24
【问题描述】:

我正在尝试在设备孪生属性更改时在云后端接收通知。为此,我设置了一条路线,如下图链接所示

https://imgur.com/a/uh0mV

我还创建了一个 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


【解决方案1】:

我使用您帖子中的代码进行了测试,它可以正常工作,因此您的路线设置和代码是正确的。

你提到过这个topic吗?我想问题和那个类似。请尝试检查帐户位置并按照 Roman Kiss 的建议进行测试。

【讨论】:

  • 感谢您的回复迈克尔。经过多次尝试使其正常工作后,我删除了我的 IoT 中心,并在欧洲西部而不是欧洲北部创建了一个新的中心,之后一切正常。也许这是服务的位置,或者是我设法激活的其他设置。无论如何,它现在有效。干杯。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-15
  • 2018-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-01
相关资源
最近更新 更多