Search code examples
c#azureiotazure-iot-hubazure-iot-edge

Azure IoT module twin update gets reverted back


My layered deployment (single module) properties read as follows:

"properties": {
        "desired": {
            "PublishInterval": 2000,
            "OtherProperty": 1
            "layeredProperties": {}
        }
},
...

After the deployment is applied I would like to add a custom property on some of the devices using the Azure portal, so the result might look like so:

"properties": {
            "desired": {
                "PublishInterval": 2000,
                "OtherProperty": 1
                "layeredProperties": {
                    "instance-specific-property": 4000
                }
            }
    },
    ...

A few minutes later this property gets reverted back and we end up with an empty layeredProperties collection.

Following up on similar questions asked here and here Im starting to think that it is not possible to do this at all and if one needs some specific properties on devices there should be a layered deployment created for that.

Is there really no way of updating a module's twin desired properties but using a deployment? Seems like an overkill.


Solution

  • So the trick is to specify the desired properties in a layered deployment that target specific property object e.g.

    "properties.desired.powerSettings": {
        "MaxChargePower": 5000,
        "MaxDischargePower": 10000
    }
    

    This is the "unchangeable" object and will get reverted back by the layered deployment. But this now allows adding additional settings to the root object (properties.desired) through e.g. Azure portal, and it would look something like this

    "properties": {
            "desired": {
                "powerSettings": {
                    "MaxChargePower": 5000,
                    "MaxDischargePower": 10000
                },
                "instance-specific-property": 4000, // new property that won't get reverted/removed by the layered deployment
    ....
    }
    

    Tested and verified - works as expected.

    ref How to configure individual modules for 100+ edge devices