0
votes

I'm working on IOT Hub device twin, and I couldn't find a way to get a notification on the device when a property is changed in the twin.

I know that there's a solution for that on the IOT Hub side, using a dedicated route, but how can I get a notification on the device when the twin has changed?

I've looked into the DeviceClient class but couldn't find anything relevant.

What am I missing?

1
you should use the SetDesiredPropertyUpdateCallbackAsync method to subscribe the notification on the desired property changes.Roman Kiss

1 Answers

0
votes

Depends on the SDK or MQTT library.

For, C, C#, Java, JS and Python you can start here:

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

From the C# doc

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);

For raw MQTT clients see https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-support#receiving-desired-properties-update-notifications

note: You will find the term "change notification events" usually referring to service side events.