Search code examples
azureazure-iot-hubazure-timeseries-insights

How to filter Azure Timeseries Insights events consumed from IoT Hub by Device ID


We have the following architecture configured:

  1. IoT Hub consumes telemetry from devices;
  2. Devices do not send their ID in the telemetry data. They only send sensor data;
  3. Timeseries Insights is set up to auto consume events from IoT Hub;
  4. A back-end web application is showing raw data from devices using TSI JSON queries.

Our issue:

At the back-end application we are trying to filter events by device ID. Here is the tricky thing. If the device ID is present in the telemetry, filtering is easy. However, what predicate should we use to filter on device ID when it is not present in the telemetry. Azure documentation defines only two built-in properties ($esn and $ts), but we can clearly see that in the response values, one of the values is the Device ID. But what is the name of the property so that we can include it in a query predicate?

Thank you!


Solution

  • I am able to query on the Iot Hub device ID by using a predicate on the property iothub-connection-device-id. See my JSON for reference

    {
        "searchSpan": {
         "from": "2018-08-02T08:00:00.000Z",
         "to": "2018-08-02T15:00:00.000Z"
        },
        "predicate" : {
            "eq": {
                "left": {
                    "property": "iothub-connection-device-id",
                    "type": "String"
                },
                "right": "my-sample-device"
            }
        },
        "top" : {
            "sort": [{
                "input" : {
                    "builtInProperty" : "$ts"
                },
                "order" : "Asc"
            }],
            "count" : 10
        }
    }