Set up MQTT¶
Open settings
The settings are openen via the SETTINGS section and in the MQTT tab.
Settings for MQTT.
If required, you can send the data collected with the CMTK via MQTT to an external database, for example. The CMTK acts as an MQTT broker whose messages an MQTT client can subscribe to. Communication is encrypted via TLS protocol (MQTT with TLS active) or unencrypted (MQTT without TLS active).
Note
The "publish" of further messages to the MQTT broker of the CMTK is not possible.
Enable and set up MQTT¶
- Activate the toggle MQTT with TLS active.
- Enter a password for the encryption of the MQTT communication in the Password field.
-
Click Save.
-
Download the certificate by Export Certificate. !!! note "Note" The values for the MQTT username and port are preset on the CMTK and can not be changed. Their values are as follows:
- Username: User
- Port: 8883 (TLS active) or 1883 (without TLS active) !!! note "Note" For security reasons we do not recommend using MQTT without TLS and without username and password. These should only be used in exceptional cases.
Subscribe to messages from CMTK as MQTT client¶
By means of a Node-RED example, it is illustrated here how you can subscribe to messages from the CMTK as an MQTT client. The implementation with other programs runs in principle comparable.
-
Use the MQTT in node with the following settings:
Topic: # (subscribes to all messages from CMTK)
Server: Enter the IP address or hostname of the CMTK.
Port: 8883
CA Certificate: Upload the certificate here via upload, see configure certificates. -
In the Security tab, enter the MQTT username and the assigned MQTT password.
-
Connect a debug node to a MQTT in-node and apply the flow.
In the debug window you get data from the connected sensors:
Topic structure and messages¶
The topic structure of the MQTT messages is shown schematically on the CMTK in the MQTT settings (tab Schema) and exemplarily on the example of a BCM0001 (tab Example). The principle structure is additionally shown in the following figure:
MQTT: Topic Structure.
The "X" in portX stands for the respective port on the CMTK or for an additionally connected IO-Link master (master2) and can therefore have the values 1 to 4 (CMTK) or 0 to 7 (IO-Link master).
For each port there are the topics:
- event: Provides information about events, e.g. connection or disconnection of a sensor.
- pd: Contains the process data of the sensors.
- unit: Returns the units for non-boolean process data.
The process data (pd) for a BCM0001 looks like this, for example:
Example process data.
Note
ts
marks the timestamp of the MQTT message. valid
indicates the validity of the measured value according to the IO-Link specification.