MQTT Commands
MQTT Control driver offers several commands to interact with an MQTT device.
Overview
Following commands are available
Command | Description | Details |
---|---|---|
mqtt:writedata | publish data to a topic | [Write Data] |
mqtt:readdata | try to receive data from a topic | [Read Data] |
mqtt:exchangedata | exchange data with a send-topic and a receive-topic | [Exchange Data] |
Address Variables
Each Address (MQTT Topic) argument supports resolving variables. All device properties are resolved as variables. See Address Variables
Command node Properties
Each command node can have the following properties
Name | Description | DataType | Necessity |
---|---|---|---|
Retain | Sends the values with the retain flag to the broker | System.Boolean | Optional |
ContentType | Special property for payload processing. See Payload Extractor | System.String | Optional |
Mapping:Value | Special property for payload processing. See Payload Extractor | System.String | Optional |
Write Data
This command allows to publish data to a specific MQTT topic.
The command address is mqtt:writedata
.
Input arguments
Name | Description | DataType | Necessity |
---|---|---|---|
Address | MQTT Topic to publish | System.String | Mandatory |
Value | Value to publish | System.String | Mandatory |
DataType | Optional value type for correct converting | System.String | Optional |
The write data command has no output arguments.
Configuration example
{
"Id": "77f3d77f-a20e-4550-9866-44ba24b8e14a",
"Name": "WriteData",
"Address": "mqtt:writedata",
"ScriptFile": "",
"Type": "CommandNode",
"Arguments": [
{
"Name": "Address",
"DataType": "System.String",
"Description": "MQTT Topic"
},
{
"Name": "Value",
"DataType": "System.String",
"Description": "Value as string"
},
{
"Name": "DataType",
"DataType": "System.String",
"Description": "Optional: DataType"
}
],
"Properties": [
{
"Name": "ContentType",
"DataType": "System.String",
"Value": "UTF8.JSON"
},
{
"Name": "Mapping:Value",
"DataType": "System.String",
"Value": "test"
},
{
"Name": "Retain",
"DataType": "System.Boolean",
"Value": "true"
}
]
}
Read Data
This command waits for a message from the broker under a specific MQTT topic.
The command address is mqtt:readdata
.
Input arguments
Name | Description | DataType | Necessity |
---|---|---|---|
Address | MQTT Topic to publish | System.String | Mandatory |
DataType | Optional value type for correct converting | System.String | Optional |
Output arguments
Name | Description | DataType | Necessity |
---|---|---|---|
Value | Value to publish | System.String | Mandatory |
Configuration example
{
"Id": "8dfdace7-e8a8-464b-9839-6fe1330d39a6",
"Name": "ReadData",
"Address": "mqtt:readdata",
"ScriptFile": "",
"Type": "CommandNode",
"Arguments": [
{
"Name": "Address",
"DataType": "System.String",
"Description": "MQTT Topic"
},
{
"Name": "Value",
"Type": "Output",
"DataType": "System.String",
"Description": "Value as string"
}
],
"Properties": [
{
"Name": "ContentType",
"DataType": "System.String",
"Value": "UTF8.JSON"
},
{
"Name": "Mapping:Value",
"DataType": "System.String",
"Value": "val"
},
{
"Name": "Retain",
"DataType": "System.Boolean",
"Value": "true"
}
]
}
Exchange Data
This command sends a message to the broker under the Request MQTT topic.
The command then waits for a response from a response topic.
Command address is mqtt:exchangedata
.
Input arguments
Name | Description | DataType | Necessity |
---|---|---|---|
RequestAddress | MQTT Topic to publish | System.String | Mandatory |
ResponseAddress | MQTT Topic to receive | System.String | Mandatory |
RequestValue | Value to publish | System.String | Mandatory |
DataType | Optional value type for correct converting | System.String | Optional |
Output arguments
Name | Description | DataType | Necessity |
---|---|---|---|
ResponseValue | Value to publish | System.String | Mandatory |
Configuration example
{
"Id": "bfefe882-efb7-4759-84f8-1757f95bf6fa",
"Name": "ExchangeData",
"Address": "mqtt:exchangedata",
"ScriptFile": "",
"Type": "CommandNode",
"Arguments": [
{
"Name": "RequestAddress",
"DataType": "System.String",
"Description": "MQTT request topic"
},
{
"Name": "ResponseAddress",
"DataType": "System.String",
"Description": "MQTT response topic"
},
{
"Name": "RequestValue",
"DataType": "System.String",
"Description": "Value to send"
},
{
"Name": "DataType",
"DataType": "System.String",
"Description": "Optional: Data type of exchanged value"
},
{
"Name": "ResponseValue",
"Type": "Output",
"DataType": "System.String",
"Description": "Received value"
}
],
"Properties": []
}