Skip to main content

MQTT

MQTT is a lightweight protocol for publishing and subscribing to messages. It is often used in IoT applications. The IoT devices publish their data to an MQTT server, which can be public or private. Importers subscribe to a topic defined in the datasource and when a message is received the content is stored on the server. The content, time and topic of the message can be imported with an importer at regular scheduled intervals, or immediately if data is received. By using an importer to pull MQTT data you can avoid system overload when MQTT devices publish information at a very high rate. When MQTT data is received the last value stored in the cache is updated so that the importer always reads the most recent value.

Datasource

The data source for an MQTT connection is defined as a secret. Create a new secret and set type to mqtt. Enter the name of IP address in the field host and optionally enter fields for username and password in case the MQTT server requires authentication. Specify the MQTT topic in the topic field. Make sure you add /# to include all sub topic if necessary.

Importer

Create a new importer and set the secret as the data source. When you Run or Test the importer the most recent topics are loaded. Define one or more objects to map the MQTT topics to topics. In the object field you enter the name of the original MQTT topic. All MQTT entries include a time field for when the event was received. Note that in this example the key is left blank because in the object mapping there is already a seperate topic for each MQTT value.

An MQTT value can be a single value like 100 or a JSON object like {"temperature": 100, "color": "red"}.