MQTT Data Access
The MQTT control plugin supports to subscribe topics from an MQTT broker using the data access info node.
Use the MQTT topic as node address.
Only one specific topic can be subscribed in a data access info. Multiple topics with topic filters are not possible. Use the MqttProcessingScript to work with topic filters.
Address Variables
The data access address (MQTT Topic) can include variables.
The values of the variables are specified as device properties in header part of device information file.
With the String $(PropertyName)
access to the properties is possible.
Example
The device contains the property ClientId
.
{
"Name": "ClientId",
"Value": "bb6ffeb6"
}
In the address (MQTT Topic), a reference is possible to the property.
Address: N/$(ClientId)/example/test
Topic subscribed by Plugin: N/bb6ffeb6/example/test
Payload Extractor
The value sent on the topic depends on the sender and can be in a specific format.
Therefore the MQTTControl plugin supports a versatile value parser to access the correct data.
With the property ContentType
on the data node, the converting behavior can be specified.
Following values are accepted by the property ContentType
ContentType | Description |
---|---|
BYTE | The value is interpreted by raw byte array. The byte array will be converted to specified data type. Data type System.String is not possible. |
UTF8 | The value is interpreted by UTF8 string. Then the String will be converted to specified data type. Array data Types are split by comma , , semicolon ; and colon : . |
UTF8.JSON | The value is interpreted by UTF8 string. Then the string will be parsed as a JSON-object. The additional Property Mapping:Value is necessary to navigate inside the JSON-object. To access sub elements of the JSON object, the mapping can be separated with a dot . . |
UTF8.XML | The value is interpreted by UTF8 string. Then the string will be parsed as an XML-object. The additional Property Mapping:Value is necessary to navigate inside the XML-object. To access elements of the XML object, use a X-Path string. |
Example
The MQTT Topic N/battery/TotalEnergy
sends the following payload
{
"timestamp": 633701682600000000,
"value": 15.7885,
"unit": "kWh"
}
The Device JSON is configured to parse the value via json mapping from the payload into the data node
{
"Id": "1D95F66E-F06D-4ED1-B9B1-A2092F141E18",
"Name": "Total Energy",
"DataType": "System.Double",
"Address": "N/battery/TotalEnergy",
"DataClass": "Event",
"Access": {
"Read": true,
"Receive": true
},
"Properties": [
{
"Name": "ContentType",
"Value": "UTF8.JSON"
},
{
"Name": "Mapping:Value",
"Value": "value"
}
]
}