Search code examples
azure-iot-hubazure-eventgrid

IoT Hub Event does not receive Azure device twin updated recorded property


IoT Hub Event does not receive recorded property changes in the device twin. For example, property ledState is updated by the actual device (with patch) and the device twin updates the reported property, but the IoT Hub Event does not receive the event. This limits me in passing this property change to a digital twin with an azure function.

The IoT Hub Event does not show updated properties, unlike telemetry which IoT Hub Event receives. Considering IoT Hub Event only receives Device Created, Deleted, Connected, Disconnected, Telemetry Event Types.

How can I get IoT Hub Events to subscribe to property updates?

Further description:

The actual device sends packet (MQTT function _nxd_mqtt_client_publish_packet_send) and I can see this logged in Termite: $iothub/twin/PATCH/properties/reported/?$rid=1121{"ledState":true} . The hub successfully responds with 204.

This is my device as shown in IoT hub and the device's ledState (reported) property is updated to true when I press button A in mxchip:

enter image description here

{
"deviceId": "mxchip",

"etag": "AAAAAAAAAF8=",
"deviceEtag": "NDY5NTIxODE1",
"status": "enabled",
"statusUpdateTime": "0001-01-01T00:00:00Z",
"connectionState": "Connected",
"lastActivityTime": "2022-09-16T14:51:32.9293466Z",
"cloudToDeviceMessageCount": 0,
"authenticationType": "sas",
"x509Thumbprint": {
    "primaryThumbprint": null,
    "secondaryThumbprint": null
},
"modelId": "dtmi:azurertos:devkit:gsgmxchip;2",
"version": 5310,
"properties": {
    "desired": {
        "telemetryInterval": 5,
        "$metadata": {
            "$lastUpdated": "2022-09-16T12:44:24.4494023Z",
            "$lastUpdatedVersion": 95,
            "telemetryInterval": {
                "$lastUpdated": "2022-09-16T12:44:24.4494023Z",
                "$lastUpdatedVersion": 95
            }
        },
        "$version": 95
    },
    "reported": {
        "deviceInformation": {
            "__t": "c",
            "manufacturer": "MXCHIP",
            "model": "AZ3166",
            "swVersion": "1.0.0",
            "osName": "Azure RTOS",
            "processorArchitecture": "Arm Cortex M4",
            "processorManufacturer": "STMicroelectronics",
            "totalStorage": 1024,
            "totalMemory": 128
        },
        "ledState": true,
        "telemetryInterval": {
            "ac": 200,
            "av": 1,
            "value": 5
        },
        "$metadata": {
            "$lastUpdated": "2022-09-16T14:55:52.6321409Z",
            "deviceInformation": {
                "$lastUpdated": "2022-09-16T13:54:57.5894378Z",
                "__t": {
                    "$lastUpdated": "2022-09-16T13:54:57.5894378Z"
                },
                "manufacturer": {
                    "$lastUpdated": "2022-09-16T13:54:57.5894378Z"
                },
                "model": {
                    "$lastUpdated": "2022-09-16T13:54:57.5894378Z"
                },
                "swVersion": {
                    "$lastUpdated": "2022-09-16T13:54:57.5894378Z"
                },
                "osName": {
                    "$lastUpdated": "2022-09-16T13:54:57.5894378Z"
                },
                "processorArchitecture": {
                    "$lastUpdated": "2022-09-16T13:54:57.5894378Z"
                },
                "processorManufacturer": {
                    "$lastUpdated": "2022-09-16T13:54:57.5894378Z"
                },
                "totalStorage": {
                    "$lastUpdated": "2022-09-16T13:54:57.5894378Z"
                },
                "totalMemory": {
                    "$lastUpdated": "2022-09-16T13:54:57.5894378Z"
                }
            },
            "ledState": {
                "$lastUpdated": "2022-09-16T14:55:52.6321409Z"
            },
            "telemetryInterval": {
                "$lastUpdated": "2022-09-16T13:54:58.1675571Z",
                "ac": {
                    "$lastUpdated": "2022-09-16T13:54:58.1675571Z"
                },
                "av": {
                    "$lastUpdated": "2022-09-16T13:54:58.1675571Z"
                },
                "value": {
                    "$lastUpdated": "2022-09-16T13:54:58.1675571Z"
                }
            }
        },
        "$version": 5215
    }
},
"capabilities": {
    "iotEdge": false
}
}

I have commented out telemetry messages in the code so only recorded property changes are sent to IoT hub but property changes don't show for Events: enter image description here


Solution

  • I'm having some trouble understanding the question, but it seems you're trying to get an Event Grid Subscription on a Twin Change event. The short answer is: you can't. Device Twin events are not supported for Event Grid.

    How can I get IoT Hub Events to subscribe to property updates?

    You mentioned that you want Device Twin changes sent to an Azure Function, you can do that by leveraging Endpoints and Message Routing. You can configure Message Routing to do that in this way: [A screenshot of the Message Routing screen

    The endpoint can be:

    • An Azure Event Hub
    • An Azure Service Bus Queue
    • An Azure Service Bus Topic
    • Blob Storage

    All of these can be used as an input to your Azure Function.