How to get Metadata / versions for sub-properties / TwinCollection?

221 views Asked by At

I´m using the Azure IoT SDK for Java DeviceTwin functionality. On calling startDeviceTwin(), I receive the reported and desired properties once in the TwinPropertyCallBack.

However, inside of the Property sent, I can only get the version of the 'root node', not for the sub-properties or TwinCollections (they are all null). On Azure Portal, I can clearly see that all of them have their own versions in the metadata section of the JSON. Example:

...
  "properties": {
    "desired": {
      "Broadcast": {
        "0": {
          "Scene": 2,
          "Brightness": 13
        }
      },
      "$metadata": {
        "$lastUpdated": "2020-12-01T07:53:53.0372127Z",
        "$lastUpdatedVersion": 17,
        "Broadcast": {
          "0": {
            "$lastUpdated": "2020-12-01T07:53:53.0372127Z",
            "$lastUpdatedVersion": 17,
            "Scene": {
              "$lastUpdated": "2020-12-01T07:53:53.0372127Z",
              "$lastUpdatedVersion": 17
            },
            "Brightness": {
              "$lastUpdated": "2020-12-01T07:28:08.5730028Z",
              "$lastUpdatedVersion": 15
            }
          },
          "$lastUpdated": "2020-12-01T07:53:53.0372127Z",
          "$lastUpdatedVersion": 17
        }
      },
      "$version": 17
    },
...

How can I receive these versions for the nested TwinCollections? Is it some configuration or is it just not supported currently?

In the above example, I want to prevent re-processing of the Brightness value, as my local state is already at 'Version 15'.

2

There are 2 answers

0
SatishBoddu On BEST ANSWER

Related Github issue posted at:Azure/azure-iot-sdk-java/issue

Below is the response from MicrosoftTeam.

The service does not send that metadata to devices by design. It is only available to service clients who request for a device's twin. In general, you will need to rely on the overall version of the document for concurrency protection.

Please comment below if you need further help in this matter.

0
iAviator On

As per the Azure documentation you should get the lastUpdatedVersion for each and every property. I'm able to get the whole metaData object including the lastUpdatedVersion in NodeJS, so similar functionality should work in Java too.