Skip to main content

MQTT

You can access data through MQTT and map it to your program variables. To do so, a new connection of type MQTT must be created.

Create new MQTT connection

logiccloud offers its own integrated MQTT broker through which you can create your connections. However, you can also connect your own broker.

logiccloud MQTT broker

To do this, click on the icon for Add logiccloud MQTT connection. In the dialog window you can enter the name Connection name, the client ID Client ID and the description Connection description .

The Reconnect period specifies how quickly a new connection is attempted when a connection is lost. Clean means that with each new connection a clean session is started without accessing previous value changes in the broker.

Protocol, Hostname and Port are automatically generated and can be used to connect to the broker.

info

The client ID should always be unique for each connection and device so that

After you have created the connection, select it in the outline tree. You will see the generated user name User name and password Password. You can use this to log in your Devices.

Install the displayed certificates on your devices to encrypt the connection.

caution

If you use the logiccloud MQTT Broker, you should install the certificates on your devices so that no security risk arises from the encrypted connection.

Own MQTT broker

The procedure is the same as when using the logiccloud MQTT broker. Click on the icon Add custom MQTT connection and fill in all the information. In addition, however, the Protocol, the Hostname, the Port as well as the authentication via User name, Password and, if necessary, certificates for the encryption must be entered.

info

The client ID should always be unique for each connection and each device, otherwise the broker may terminate the connection.

Define MQTT Payload

The MQTT payload maps the MQTT messages to the logiccloud access variables.

For this purpose, a new payload must be created within the previously created connection via the icon Add payload .

To do this, specify the name Payload name and the description Payload description .

JSON Payload

For the JSON payload, you still need to define the content of the payload so that it can be understood by logiccloud. In the selection fields you will find ready-made templates to decrypt the payload. You can use these, but also define your own structures.

In the lower area the formats can be tested. For this you can define the Read format , select Test Read/Write read and copy your JSON Payload into the left area. If you use placeholders with ##tag## , you can set the example tags at tag . In the right window you can see which value from the JSON payload corresponds to the defined Read format . The same applies to the Write format.

caution

The formats for reading and writing must be identical so that the variables can be processed accordingly by logiccloud. This means that the structure of the payload to be read and the payload to be written must be identical. If you need different formats for different variables, you can define several different payloads and assign them to the variables.

Read values

Beispiele
$[data]
// sample payload
{
"data": 11.245
}

$[value]
// sample payload
{
"value": 123.678
}

$[data][##tag##]
// sample payload
{
"data": {
"tagName": 34.567
}
}

Write values

Beispiele
{"data":##v##}
// sample payload
{
"data": 11.245
}

{"name": "##tag##", "value":##v##}
// sample payload
{
"value": 123.678
}

{"data": {"##tag##": ##v##}
// sample payload
{
"data": {
"tagName": 34.567
}
}

Map MQTT variables

Within the payload at Payload Mapping you can map the variables from your logiccloud projects with the MQTT tags.

To do this, create a new mapping via the + icon. To do this, select the variable , insert the tag name from the MQTT payload, select the data type and the topic. The first part of the topic is always predefined and consists of the Runtime ID and the MQTT Connection. The rest of the MQTT topic can be freely defined.

info

The data types in MQTT are slightly different from the data types in Structured Text. Therefore, you should select the MQTT data type that corresponds to the data type of ST.

After you have created the mappings, you can start your runtime.