Search code examples
azure-iot-hubazure-iot-sdk

Device Twin Properties naming convention in documentation contradics with Python SDK


I want to change a "desired" property of an Device Twin in Iot-Hub.

I want the element name of the property to be an integer value, e.g.:

"properties": {
  "desired": {
    "24": 21,
    ...
 ...
}

According to the Documentation this seems to be ok. Also when adding a property with that key to the device Twin in the Webportal this works.

However, using the Python SDK this seems to be illegal:

    patch = [{"op": "add", "path": "/24", "value": 11.3}]
    digital_twin_client.update_digital_twin(device_id, patch)

results in:

HttpOperationError error {"Message":"ErrorCode:ArgumentInvalid;Digital twin element name 24 is invalid. Name must be 64 characters or less and match ^[a-zA-Z](?:[a-zA-Z0-9_]*[a-zA-Z0-9])?$ regular expression.","ExceptionMessage":"Tracking ID:d906ded47b084e75afc9992a06df7c77-G:33-TimeStamp:12/11/2020 12:20:07"}

Which one is correct?


Solution

  • If you want to update the desired properties of a Device Twin, you need to use the Registry Manager. Please see this sample. You're currently trying to use the Digital Twin Client, which does not affect the Device Twin.

    The device twin does indeed support your case (just tested it myself). So you will have no trouble naming your key the name "24".