MQTT in plain words
MQTT works like a notice board with a clerk. Devices pin messages under a subject. Anyone interested in that subject has told the clerk once and gets a copy of every new message. Nobody has to know who else is reading.
In MQTT terms the clerk is the broker, the subject is the topic, pinning a message is publishing and asking for copies is subscribing. Every device and application is a client. The OASIS standard calls MQTT "a Client Server publish/subscribe messaging transport protocol", designed to be lightweight, open, simple and easy to implement [1].
MQTT was invented in 1999 by Andy Stanford-Clark of IBM and Arlen Nipper of Arcom, now Eurotech [2]. Version 3.1.1 is also an ISO standard, ISO/IEC 20922:2016 [3]. Version 5.0 followed as an OASIS standard on 7 March 2019 [1].
How MQTT works
- Connect. A client opens a TCP connection to the broker and sends CONNECT with a client ID, usually with a username and password or a certificate.
- Publish. A gas analyzer gateway publishes the topic
plant1/raw-gas/ch4with the payload52.4. - Subscribe. A dashboard subscribes to
plant1/#and receives everything belowplant1. - Forward. The broker passes each message to every matching subscriber.
- Stay alive. Client and broker exchange small ping packets when nothing else is sent. If the broker hears nothing for one and a half times the keep-alive period, it closes the connection as if the network had failed [1].
MQTT needs a transport that delivers an ordered, lossless stream of bytes in both directions: TCP, TLS or WebSocket. UDP is not suitable [1]. The smallest MQTT packet header is two bytes.
Topics and wildcards
Topics are text with levels separated by /. Subscribers can use two wildcards [1]:
| Filter | Matches | Does not match |
|---|---|---|
plant1/+/ch4 (+ = exactly one level) |
plant1/raw-gas/ch4, plant1/product-gas/ch4 |
plant1/raw-gas/line2/ch4 |
plant1/# (# = any number of levels, must be last) |
plant1, plant1/raw-gas/ch4, plant1/flare/temp |
plant2/raw-gas/ch4 |
Quality of service: QoS 0, 1 and 2
| QoS | Name in the standard | Guarantee | Packets per message | Typical use |
|---|---|---|---|---|
| 0 | At most once | Delivered once or not at all | 1 | Fast values where the next one follows soon |
| 1 | At least once | Always arrives, may arrive twice | 2 (PUBLISH, PUBACK) | Measurements that must not be lost |
| 2 | Exactly once | Arrives exactly once | 4 (PUBLISH, PUBREC, PUBREL, PUBCOMP) | Commands, counters, billing events |
QoS applies on each hop separately: publisher to broker, broker to subscriber. A subscriber gets at most the QoS it asked for. A QoS 2 message to a subscriber with QoS 1 is downgraded and may arrive twice [1].
Features plants rely on
- Retained messages. The broker keeps the last message on a topic and hands it to every new subscriber at once. Good for current states. An empty retained message deletes it [1].
- Last Will. A message the broker publishes on a client's behalf when its connection breaks without a clean goodbye. Typical use: an "offline" status [1].
- Persistent sessions. The broker keeps a client's subscriptions and its pending QoS 1 and 2 messages across reconnects. MQTT 5 sets how long with the Session Expiry Interval [1].
- Keep alive. Detects dead connections, even when a mobile network drops silently.
What MQTT 5 added
| Feature | What it does |
|---|---|
| Session expiry | Replaces the old clean-session flag with a time limit for sessions |
| Message expiry | A message can carry a lifetime. Stale commands are dropped. |
| Reason codes on all acknowledgements | The sender learns why something failed, not just that it did |
| User properties | Name-value pairs on a message, for example a message ID or device serial |
| Topic alias | Replaces a long topic with a small number to save bytes |
| Shared subscriptions | $share/{group}/{filter} spreads messages across several consumers |
| Flow control | Each side states how many unacknowledged QoS 1 and 2 messages it accepts |
| Payload format and content type | Marks a payload as text or binary and names its type |
| Request/response | Response topic and correlation data for replies |
Selection from the summary of new features in the MQTT 5.0 standard, Appendix C [1].
MQTT vs Modbus, OPC UA and HTTP
| MQTT | Modbus TCP | OPC UA | HTTP/REST | |
|---|---|---|---|---|
| Pattern | Publish/subscribe through a broker | Client polls each device | Client/server, plus publish/subscribe | Request/response |
| Data model | None, the payload is free | Bits and 16-bit registers | Rich information model | None |
| Connection | Every client connects out to the broker | Client connects to each device on port 502 | Client to server, typically port 4840 | Client to server, port 443 |
| Security | TLS on 8883, logins at the broker | None in the base protocol | Signing, encryption and certificates built in | TLS |
| Best at | Many devices, weak links, firewalls | Simple field devices | Semantics and interoperability | Web and IT systems |
MQTT is "agnostic to the content of the payload" [1]. That is its strength and its weakness. Modbus is covered in Modbus TCP vs RTU.
MQTT in industry: Sparkplug
Because the payload is free, two systems can both speak MQTT and still not understand each other. Eclipse Sparkplug closes that gap for industrial use. It defines a topic namespace, a binary payload format, birth and death messages for device state, and report by exception. Sparkplug 3.0 is published as ISO/IEC 20237:2023 [4].
Security checklist
- Encrypt. TLS on port 8883. Plain 1883 belongs on a closed local network at most.
- No anonymous access. One login per device or gateway, so a single one can be revoked.
- Authorize. The standard expects brokers to check whether a client may use its client ID [1]. Brokers can also limit which topics each client may publish or subscribe to.
- Connect outward. Devices open the connection to the broker. The plant firewall needs no inbound port.
- Separate networks. Keep the gateway between the control network and the internet, in line with NIST SP 800-82r3 zones [5].
MQTT pitfalls
- Duplicates under QoS 1. "At least once" means sometimes twice. Give each message an ID and drop repeats.
- Stale retained values. A retained message can be days old. Put the measurement time in the payload. MQTT itself carries no timestamp.
- Topic sprawl. Define the topic structure before the first device, not after the fiftieth.
- No payload contract. Agree on format and units, or use Sparkplug.
- Lost data during outages. QoS only works while a connection exists. A gateway needs its own disk buffer for longer outages.
How Factory uses MQTT 5
The Factory connector is a working example of the points above:
- It connects out to the Factory broker over MQTT 5 with TLS on port 8883. Every connector has its own login. There is no anonymous access and no inbound port at the plant.
- Every analyzer reading goes out with QoS 1. MQTT 5 user properties carry a message ID, the device serial and the device type, so the platform can drop duplicates and knows the source.
- The connector registers a Last Will. If its connection breaks, the broker itself publishes the connector's offline status, without the connector doing anything.
- Its session persists across reconnects. It respects the broker's flow-control limit.
- While the line is down, readings wait on disk, up to 2 GiB. The backlog goes out at a pace the platform sets once the line is back.
Today the connector reads Fresenius Instruments gas analyzers. Coming 2027: Factory Studio also takes values from other MQTT devices, next to Modbus, OPC UA, Siemens S7 and BACnet.
Sources
- OASIS, MQTT Version 5.0, OASIS Standard, 7 March 2019, sections 1, 3, 4.2, 4.7 and Appendix C. docs.oasis-open.org
- mqtt.org, FAQ. mqtt.org
- ISO/IEC 20922:2016, Message Queuing Telemetry Transport (MQTT) v3.1.1. iso.org
- ISO/IEC 20237:2023, Sparkplug 3.0; Eclipse Foundation announcement. iso.org
- NIST SP 800-82r3, Guide to Operational Technology (OT) Security, September 2023, chapter 5. nvlpubs.nist.gov
FAQ
What does MQTT stand for?
MQTT began as MQ Telemetry Transport in IBM's early specification, named after IBM's MQ products. Today it is simply the name of the protocol. The OASIS standard is titled just MQTT Version 5.0. The expansion Message Queuing Telemetry Transport still appears, for example in the name of the OASIS committee and in the ISO title. It is misleading: MQTT is publish/subscribe, not a message queue.
Which port does MQTT use?
TCP port 1883 for plain MQTT and 8883 for MQTT over TLS. Both are registered with IANA. Use 8883 whenever data leaves a local network.
Is MQTT secure?
MQTT itself only carries messages. Security comes from TLS encryption, a login per device, topic permissions on the broker and connections that open outbound from the plant. Plain MQTT on port 1883 over the internet is not secure.
What is the difference between MQTT and HTTP?
HTTP is request/response: a client asks, a server answers, then the exchange is over. MQTT keeps one connection open to a broker and pushes each message to every subscriber as it arrives, with small headers of two bytes minimum. That suits many devices sending small values often.
What is an MQTT broker?
The server in the middle. It accepts connections from all clients, checks their logins, receives every published message and forwards it to the clients subscribed to that topic. It also keeps retained messages and sessions.
Does Factory use MQTT?
Yes. The Factory connector sends every analyzer reading to Factory over MQTT 5 with TLS on port 8883, with QoS 1, its own login and a buffer of up to 2 GiB on disk.
Fresenius Instruments editorial team
We build gas analyzers in Herten, Germany, and the software that connects them. Write to us
