Skip to main content
Version: 2.7

MQTT Commands

MQTT Control driver offers several commands to interact with an MQTT device.

Overview

Following commands are available

CommandDescriptionDetails
mqtt:writedatapublish data to a topic[Write Data]
mqtt:readdatatry to receive data from a topic[Read Data]
mqtt:exchangedataexchange 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

NameDescriptionDataTypeNecessity
RetainSends the values with the retain flag to the brokerSystem.BooleanOptional
ContentTypeSpecial property for payload processing. See Payload ExtractorSystem.StringOptional
Mapping:ValueSpecial property for payload processing. See Payload ExtractorSystem.StringOptional

Write Data

This command allows to publish data to a specific MQTT topic. The command address is mqtt:writedata.

Input arguments

NameDescriptionDataTypeNecessity
AddressMQTT Topic to publishSystem.StringMandatory
ValueValue to publishSystem.StringMandatory
DataTypeOptional value type for correct convertingSystem.StringOptional

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

NameDescriptionDataTypeNecessity
AddressMQTT Topic to publishSystem.StringMandatory
DataTypeOptional value type for correct convertingSystem.StringOptional

Output arguments

NameDescriptionDataTypeNecessity
ValueValue to publishSystem.StringMandatory

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

NameDescriptionDataTypeNecessity
RequestAddressMQTT Topic to publishSystem.StringMandatory
ResponseAddressMQTT Topic to receiveSystem.StringMandatory
RequestValueValue to publishSystem.StringMandatory
DataTypeOptional value type for correct convertingSystem.StringOptional

Output arguments

NameDescriptionDataTypeNecessity
ResponseValueValue to publishSystem.StringMandatory

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": []
}