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

SettingWhat it does
NameIdentifies the device (with an optional custom name).
EnabledWhether THMI connects to the broker. Turn it off to stop communication and value collection without deleting it.
Base topicA prefix added to the topics of individual tags, so each tag only needs its sub-topic.
ProtocolHow THMI connects to the broker: MQTTS (TLS, recommended), MQTT (plain), WSS (MQTT over secure WebSocket), or WS (plain WebSocket).
HostThe hostname or IP address of the broker.
PortThe broker port — commonly 8883 for MQTTS or 1883 for MQTT.
Username / passwordCredentials, 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-topicDirectionPayload
{base topic}/{topic}/readbroker → THMI (value){ "v": <value> }
{base topic}/{topic}/writeTHMI → 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).