Search code examples
azureazure-iot-hubazure-iot-sdk

Azure IoT Devices Receiving Twin Update Notifications


I tried to receive desired properties update notifications by subscribing topic "$iothub/twin/PATCH/properties/#" (reference) and also by sdk (refernece). Both went okay and I did get notifications when I changed the desired properties by back-end services, but with all the desired properties in response. Is there a topic or a function in sdk to just get the properties that where changed? Or to know witch properties were changed without looking through all the desired properties?

Appreciate your help!


Solution

  • You should use a PATCH request to update a desired property in your back-end service. The following screen snippets show an example of the updating only one desired property such as color. For quick demonstration purpose, the Azure IoT Hub Tester is used:

    1. Creating two desired properties (color, abc): enter image description here

    2. device8 received a changes notification (version=2): enter image description here

    3. In this step, we need to update only one desired property (color): enter image description here

    4. device8 received a changes notification (version=3) such as the preperty color: enter image description here

    As you can see in the above pictures, the device8 subscribed on the topic like you mentioned it. You didn't describe how your backend service updating your desired properties.

    Note, that the above example using the REST PATCH call for updating a desired properties.