Share via

Azure IotHub deviceTwin property changes

Anonymous
2023-07-10T04:32:06.75+00:00

We are currently facing an issue with our configured Event Hub, which is set up to listen for changes in the IoT Hub device twin. Our problem arises when we update the reported section of the device twin. We have noticed that the tags associated with the device twin are not included in the payload message received by the Event Hub, though the message enrichment for the same tag value is configured in the iothub under message routes. However, when we update the desired property of the device twin, the tags are correctly included in the message sent to the Event Hub.

I have created an IoT device and specified some tags in the Identity Twin of the device.

"tags": { "deviceId": "", "deviceLocation": { "latLong": [], "city": "" }, "tenantCode": "" },

I have defined message enrichments and routes in IoT Hub based on the tags that I've added. Below is the sample response message we got from the event hub when we updated the reported session of the device twin.

{"version":7,"properties":{"reported":{"deviceInformation":{"ProcessorManufacturer":"STMicroelectronics","manufacturer":"MXCHIP","processArchitecture":"Arm Cortex M4","osName":"Azure RTOS","totalStorage":1234,"model":"AZ3166","swVersion":"1.0.0","totalMemory":128},"$metadata":{"$lastUpdated":"2023-06-19T12:55:31.9240242Z","deviceInformation":{"$lastUpdated":"2023-06-19T12:55:31.9240242Z","ProcessorManufacturer":{"$lastUpdated":"2023-06-19T12:55:31.9240242Z"},"manufacturer":{"$lastUpdated":"2023-06-19T12:55:31.9240242Z"},"processArchitecture":{"$lastUpdated":"2023-06-19T12:55:31.9240242Z"},"osName":{"$lastUpdated":"2023-06-19T12:55:31.9240242Z"},"totalStorage":{"$lastUpdated":"2023-06-19T12:55:31.9240242Z"},"model":{"$lastUpdated":"2023-06-19T12:55:31.9240242Z"},"swVersion":{"$lastUpdated":"2023-06-19T12:55:31.9240242Z"},"totalMemory":{"$lastUpdated":"2023-06-19T12:55:31.9240242Z"}}},"$version":3}}}.

And the following response message we got from the eventhub when we updated the desired properties of the device twin.

{\n 'version': 7,\n 'tags': {\n 'deviceId': 'b7a8b56219',\n 'deviceLocation': {\n 'latLong': [\n '0',\n '0'\n ],\n 'city': ' '\n },\n 'tenantCode': 'FC1ADB3485'\n },\n 'properties': {\n 'desired': {\n 'attendanceSettings': {\n 'screenPinningEnabled': true,\n 'isGPSEnabled': false,\n '__t': 'c',\n 'offlineMode': true,\n 'cameraMode': 'BACK',\n 'attendanceEntryMode': 'AUTO',\n 'heartbeatInterval': 30\n },\n '$metadata': {\n '$lastUpdated': '2023-07-10T04:27:51.0860394Z',\n '$lastUpdatedVersion': 3,\n 'attendanceSettings': {\n '$lastUpdated': '2023-07-10T04:27:51.0860394Z',\n '$lastUpdatedVersion': 3,\n 'screenPinningEnabled': {\n '$lastUpdated': '2023-07-10T04:27:51.0860394Z',\n '$lastUpdatedVersion': 3\n },\n 'isGPSEnabled': {\n '$lastUpdated': '2023-07-10T04:27:51.0860394Z',\n '$lastUpdatedVersion': 3\n },\n '__t': {\n '$lastUpdated': '2023-07-10T04:27:51.0860394Z',\n '$lastUpdatedVersion': 3\n },\n 'offlineMode': {\n '$lastUpdated': '2023-07-10T04:27:51.0860394Z',\n '$lastUpdatedVersion': 3\n },\n 'cameraMode': {\n '$lastUpdated': '2023-07-10T04:27:51.0860394Z',\n '$lastUpdatedVersion': 3\n },\n 'attendanceEntryMode': {\n '$lastUpdated': '2023-07-10T04:27:51.0860394Z',\n '$lastUpdatedVersion': 3\n },\n 'heartbeatInterval': {\n '$lastUpdated': '2023-07-10T04:27:51.0860394Z',\n '$lastUpdatedVersion': 3\n }\n }\n },\n '$version': 3\n }\n }\n}'

We kindly request your assistance in resolving this matter

The payload message received by the Event Hub when the reported property is updated, we would expect the tags associated with the device twin to be included in the message sent to the Event Hub, along with the changes made in the reported section.

Azure IoT Hub
Azure IoT Hub

An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.


1 answer

Sort by: Most helpful
  1. Sander van de Velde | MVP 37,066 Reputation points MVP
    2023-07-10T21:05:14.12+00:00

    Hello @Praveen E,

    It can take a few minutes before device twin changes are seen in the output.

    Next to that, message enrichments are not added to the body, these are put in the application/user properties.

    Do you alter the tags using the Azure Portal? Pleach check if these changed tags are actually updated. A typo is easy to make and the Device Twin Editor is very keen on dropping incorrectly formatted JSON device twins.


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.

    Was this answer helpful?

    0 comments No comments

Your answer

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