Properly Create a Device Template from a Live Device in Azure IOT Central

114 views Asked by At

I have LoRaWAN IoT devices from the TTN network, which I have brought to Azure IoT Central. I would like to get specific data inside the JSON in order to make alert rules. Here is a sample of the JSON I receive from a Milesight PIR & Light Sensor. Suppose I only want to get the "battery", "daylight" and "pir" values to make the alert, how do I go about that?

{
    "end_device_ids": {
        "device_id": "eui-24e124538c195063",
        "application_ids": {
            "application_id": "test-1117"
        },
        "dev_eui": "24E124538C195063",
        "join_eui": "24E124C0002A0001",
        "dev_addr": "260D82F3"
    },
    "received_at": "2023-02-01T13:52:47.892042526Z",
    "uplink_message": {
        "session_key_id": "AYYLj9wg6AeehHWwDLrzLg==",
        "f_port": 85,
        "f_cnt": 38,
        "frm_payload": "AXVkAwAABAAA",
        "decoded_payload": {
            "battery": 100,
            "daylight": "dark",
            "pir": "normal"
        },
        "rx_metadata": [
            {
                "gateway_ids": {
                    "gateway_id": "eui-24e124fffef5531c",
                    "eui": "24E124FFFEF5531C"
                },
                "time": "2023-02-01T13:52:47.429725885Z",
                "timestamp": 2696081442,
                "rssi": -64,
                "channel_rssi": -64,
                "snr": 13,
                "uplink_token": "CiIKIAoUZXVpLTI0ZTEyNGZmZmVmNTUzMWMSCCThJP/+9VMcEKLgy4UKGgwIr93pngYQ94rGxQIg0Ino17uJFw==",
                "received_at": "2023-02-01T13:52:47.596682842Z"
            }
        ],
        "settings": {
            "data_rate": {
                "lora": {
                    "bandwidth": 125000,
                    "spreading_factor": 7,
                    "coding_rate": "4/5"
                }
            },
            "frequency": "867700000",
            "timestamp": 2696081442,
            "time": "2023-02-01T13:52:47.429725885Z"
        },
        "received_at": "2023-02-01T13:52:47.683989041Z",
        "confirmed": true,
        "consumed_airtime": "0.061696s",
        "network_ids": {
            "net_id": "000013",
            "tenant_id": "ttn",
            "cluster_id": "au1",
            "cluster_address": "au1.cloud.thethings.network"
        }
    },
    "_eventtype": "Telemetry",
    "_timestamp": "2023-02-01T13:52:49.35Z"
}
1

There are 1 answers

0
Ziggy On

I was able to get the values by uploading my own DTDL.

Once the device sends data to Azure IOT Central from TTN, the device will have no template.

  1. I first created a template from the raw telemetry sent.
  2. I went to the new device template created, clicked EDIT DTDL, then placed the following JSON:
{
    "@id": "dtmi:telavi:eui24e124538c195063;1",
    "@type": "Interface",
    "contents": [
        {
            "@type": [
                "Telemetry",
                "DateTimeValue"
            ],
            "displayName": {
                "en": "received_at"
            },
            "name": "received_at",
            "schema": "dateTime"
        },
        {
            "@type": [
                "Telemetry",
                "NumberValue"
            ],
            "description": {
                "en": "battery"
            },
            "displayName": {
                "en": "battery"
            },
            "name": "battery",
            "schema": "integer"
        },
        {
            "@type": [
                "Telemetry",
                "StringValue"
            ],
            "description": {
                "en": "daylight"
            },
            "displayName": {
                "en": "daylight"
            },
            "name": "daylight",
            "schema": "string"
        },
        {
            "@type": [
                "Telemetry",
                "StringValue"
            ],
            "description": {
                "en": "pir"
            },
            "displayName": {
                "en": "pir"
            },
            "name": "pir",
            "schema": "string"
        }
    ],
    "displayName": {
        "en": "eui-24e124538c195063"
    },
    "@context": [
        "dtmi:iotcentral:context;2",
        "dtmi:dtdl:context;2"
    ]
}