【问题标题】:Change notification in Azure IOT Hub device twinAzure IOT Hub 设备孪生中的更改通知
【发布时间】:2021-05-07 09:48:01
【问题描述】:

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

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

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

我错过了什么?

【问题讨论】:

  • 您应该使用 SetDesiredPropertyUpdateCallbackAsync 方法来订阅所需属性更改的通知。

标签: azure-iot-hub


【解决方案1】:

取决于 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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-15
    • 1970-01-01
    • 2022-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多