Understanding telemetry message and properties in Azure IoT
In this article, you will learn about telemetry and how to add user-defined and system message properties.
What is a telemetry in Azure IoT?
In short a telemetry message from a device to an Azure IoT Hub consists of:
-
Body, the actual data from the IoT device. Parameter name:
body
-
System properties, meta data about the message and connection: Parameter name:
systemProperties
-
Message properties, custom properties set by the developer of the IoT device. Parameter name:
properties
When sending telemetry messages to Azure IoT Hub you send a body which is normally in JSON. An example could be:
{
"temperature": 23.4
"humidity": 45
}
which defines information relevant to process and store in Azure. Additionally a message also contains system properties populated by Azure IoT and message properties which the user can define.
A full message which includes the system properties and the message properties could look as follows:
{ "body": "{ \"temperature\": 23.4 \"humidity\": 45 }", "enqueuedTime": "Tue Dec 17 2024 14:28:20 GMT+0100 (Central European Standard Time)",
"properties": { "alarm_level": "info",
"priority": "low" },
"sequenceNumber": 576603, "systemProperties": { "iothub-message-source": "Telemetry", "iothub-connection-device-id": "DemoSIA", "iothub-connection-auth-method": "{\"scope\":\"device\",\"type\":\"sas\",\"issuer\":\"iothub\"}", "iothub-connection-auth-generation-id": "637480328383432313", "iothub-enqueuedtime": 1734442100314, "x-opt-sequence-number-epoch": -1 } }
Message properties
A message property defines the meta data of the message which an Azure function can use to filter or do other processing with but can be discarded afterwards. Its primarily function is to act as message routing together with routing rules and for processing of the message.
The message properties are transmitted within the telemetry message in the following example you can see the message
parameter which defines the properties:
{
....
"properties": {
"Facility": "Bottle_plant",
"Floor": "1"
},
....
}
which defines a location for the given sensor and can be used in Azure for message routing rules or processing of the telemetry message.
How to add system properties for content-encoding and content-type to telemetry
Additionally you can also add custom system properties in the telemetry by defining them in the message properties in SIA Connect such as system properties for content-encoding
and content-type
.
To define the content-encoding and content-type you need to apply the following message property format:
{
"$.ce": "utf-8",
"$.ct": "application/json"
}
together with any additional custom message properties you would like. Where $.ce
defines the content-encoding and $.ct
defines the content-type.
This would add below properties to the system properties in the telemetry message:
{
....
"systemProperties": {
....
"contentType": "application/json",
"contentEncoding": "utf-8"
}
}