MQTT
Connect to an MQTT broker and read values published to topics, with optional QoS and encryption.
MQTT reads values published to topics on an MQTT broker. You connect to the broker once and create a tag for each topic you want to read.
Connecting to a broker
| Setting | What it does |
|---|---|
| Name | Identifies the device (with an optional custom name). |
| Enabled | Whether THMI connects to the broker. Turn it off to stop communication and value collection without deleting it. |
| Base topic | A prefix added to the topics of individual tags, so each tag only needs its sub-topic. |
| Protocol | How THMI connects to the broker: MQTTS (TLS, recommended), MQTT (plain), WSS (MQTT over secure WebSocket), or WS (plain WebSocket). |
| Host | The hostname or IP address of the broker. |
| Port | The broker port — commonly 8883 for MQTTS or 1883 for MQTT. |
| Username / password | Credentials, if the broker requires them. |
Quality of Service and retained messages
- Quality of Service (QoS) — how reliably messages are delivered: 0 – at most once, 1 – at least once, or 2 – exactly once. Higher levels give greater assurance of receipt at the cost of more traffic.
- Retained — ensures the last message on a topic is kept by the broker and delivered to new subscribers as soon as they connect, so a tag has a value immediately rather than waiting for the next publish.
- Receipt acknowledgement — sends an acknowledgement on successful receipt; required for QoS 1 and QoS 2 to work correctly on the target device.
Data encryption
Optionally enable data encryption for payloads, choosing an algorithm (AES or DES) and supplying the key and initialization vector (their required sizes depend on the algorithm).
Health check
Optionally enable a health check that periodically verifies the connection, with an interval (default 60 seconds) and a timeout (default 10 seconds).
Reading a value: the topic
Each MQTT tag reads one topic, appended to the device’s base topic. THMI treats a value’s topic as a base and exchanges JSON messages on two sub-topics underneath it:
| Sub-topic | Direction | Payload |
|---|---|---|
{base topic}/{topic}/read | broker → THMI (value) | { "v": <value> } |
{base topic}/{topic}/write | THMI → broker (writes) | { "v": <value> } |
So a tag with base topic building-a and topic boiler/temp reads from
building-a/boiler/temp/read. Set the data type to match the published
value (see Data types). Writable lets
users with permission publish a value on the …/write sub-topic (see
Values).