首页 > 解决方案 > Azure IOT Hub 设备孪生中的更改通知

问题描述

我正在研究 IOT Hub 设备双胞胎,当双胞胎中的属性发生更改时,我找不到在设备上获取通知的方法。

我知道在 IOT 集线器端有一个解决方案,使用专用路由,但是当双胞胎发生变化时,如何在设备上获得通知?

我查看了 DeviceClient 类,但找不到任何相关内容。

我错过了什么?

标签: azure-iot-hub

解决方案


取决于 SDK 或 MQTT 库。

对于 C、C#、Java、JS 和 Python,您可以从这里开始:

https://docs.microsoft.com/en-us/azure/iot-pnp/concepts-developer-guide-device?pivots=programming-language-csharp#implement-telemetry,-properties,-and-commands

来自 C# 文档

await client.SetDesiredPropertyUpdateCallbackAsync(async (desired, ctx) => { JValue targetTempJson = desired["targetTemperature"]; double targetTemperature = targetTempJson.Value();

TwinCollection reportedProperties = new TwinCollection(); TwinCollection ackProps = new TwinCollection(); ackProps["value"] = targetTemperature; ackProps["ac"] = 200; ackProps["av"] = desired.Version; ackProps["ad"] = "desired property received"; reportedProperties["targetTemperature"] = ackProps;

await client.UpdateReportedPropertiesAsync(reportedProperties); }, null);

对于原始 MQTT 客户端,请参阅 https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-support#receiving-desired-properties-update-notifications

注意:您会发现术语“更改通知事件”通常指的是服务端事件。


推荐阅读