How to update a certain desired twin property of an Azure IoT Hub Module?

GARCIA VAZQUEZ Miguel Angel 6 Reputation points
2022-05-31T12:34:39.437+00:00

Hi everyone,

im trying to use Java sdk in order to update desired properties on my IoT Hub Module but only can modify the reported properties.
All examples i can found with Java sdk are to update desired properties for a deviceId (without module).

https://github.com/Azure/azure-iot-sdk-java

Another solution it would be to use azure rest api https://learn.microsoft.com/es-es/rest/api/iothub/service/modules/update-twin but i don't want to send all desired properties in the request (only updates example: properties.desired.PublishInterval = 1000)

Thanks

Azure IoT Edge
Azure IoT Edge
An Azure service that is used to deploy cloud workloads to run on internet of things (IoT) edge devices via standard containers.
599 questions
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,274 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. GARCIA VAZQUEZ Miguel Angel 6 Reputation points
    2022-06-02T06:28:23.917+00:00

    Finally i have found the solution to update the twin-module desired properties ,

    DeviceTwinDevice constructor can be used with a deviceId and moduleId, so example below:

    DeviceTwin twinClient = DeviceTwin.createFromConnectionString(connectionString);
    DeviceTwinDevice twin = new DeviceTwinDevice(deviceId,moduleId);
    twinClient.getTwin(twin);

    //Get the module desired properties
    Set<com.microsoft.azure.sdk.iot.service.devicetwin.Pair> properties = twin.getDesiredProperties();
    //..
    //Logic to modify the properties
    //..

    //Set the desired properties
    twin.setDesiredProperties(properties);

    //Update the twin module with the new desired properties
    twinClient.updateTwin(twin);

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.