azure-iot-hub - Azure IOT Hub 设备孪生中的更改通知
问题描述
我正在研究 IOT Hub 设备双胞胎,当双胞胎中的属性发生更改时,我找不到在设备上获取通知的方法。
我知道在 IOT 集线器端有一个解决方案,使用专用路由,但是当双胞胎发生变化时,如何在设备上获得通知?
我查看了 DeviceClient 类,但找不到任何相关内容。
我错过了什么?
解决方案
取决于 SDK 或 MQTT 库。
对于 C、C#、Java、JS 和 Python,您可以从这里开始:
来自 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
注意:您会发现术语“更改通知事件”通常指的是服务端事件。
推荐阅读
- reactjs - Convert Element or SVGSVGElement to string and keep mouseover, mouseout events
- python - 使用python从couchbase集合中提取文档
- c# - Get json in request body with ASP.NET MVC
- php - pdo has too many INACTIVE connections on oracle 19c and php 7
- windows - Running SMB (File Share) in a Windows Server Container
- sip - How to specify tshark script what interface to capture on
- proxy - Is there any way to listen for the call of native object's method?
- html - z-index is not working with pseudo elements
- java - Android Studio: move a activity to separate java class
- apache-spark - HIVE output shows timestamps are being converted to UTC