← engineering notebook

Moving to MQTT 5: what the new version changes for a device

2 May 2026 · updated 28 November 2026 · 6 min read · mqtt · protocol · firmware
The Cube, royal blue with black edges, looks at a document on its right; on its left, radio waves.

When a connected device has a message rejected, does it know why? With the version of MQTT that most devices still speak, the answer is often no. Version 5 of the protocol fixes that, and a good deal more. We wanted to know what it really brought to a small device, and what it cost.

Update of 28 November 2026.

Since 20 November, the connected Cube has been speaking MQTT over 4G, but not in the way this article envisaged. In the end we handed the protocol to the modem of the Walter board, which the firmware drives with commands, rather than running MQTT and TLS encryption in the microcontroller. The firmware itself configures verification of the server’s certificate, name included, and the Cube presents its own certificate (see One identity per Cube).

Part of what we were asking of MQTT 5 is now handled above the protocol. Every message is sealed by the application: signed by the Cube, encrypted for the server and numbered to prevent replay (see the article on post-quantum cryptography). A status whose signed time is more than five minutes away from the server’s does not count as evidence that the Cube is online, and a command relayed over 4G is valid for only two minutes. We do not use MQTT’s Last Will, the message the broker publishes when a device disappears: LTE-M, the 4G variant for connected devices, has short dropouts, and the length of the silence is what decides the alert.

Recovering after a dropout came back to bite us on 25 November. The broker closed the Cube’s connection after a minute and a half of radio silence, the modem reconnected with a new session, and the Cube’s subscriptions were lost without the firmware noticing. For more than an hour, the server’s messages did not reach it. The Cube now renews its subscriptions every ten minutes. The broker is still Mosquitto. The proportion of time during which the Cube reaches the server is one of the metrics proposed in Making a connected device last, and what becomes of a device when its cellular network shuts down is the subject of an article of its own.

The problem: a lean protocol, sometimes too lean

MQTT is a messaging protocol designed for devices: each device publishes messages to named topics, and a central server, the broker, passes them on to those that have subscribed. The most widely used version, 3.1.1, is an OASIS standard from 2014. It is remarkably lean, and that is its chief virtue, but this leanness leaves several questions unanswered as soon as a fleet grows.

A device whose connection is refused gets one of a handful of codes, and a device whose publish is rejected is often told nothing at all. A message has no expiry date, so an order left in a queue during a dropout can arrive hours later, when it no longer makes sense. Finally, there is nowhere set aside for metadata: if you want to say where a message comes from or which request it answers, you have to slip it into the payload and agree on it among yourselves.

What version 5 adds

MQTT 5.0 became an OASIS standard in March 2019. Its Appendix C lists what is new; here we pick out the features that matter for a device.

NeedMQTT 3.1.1MQTT 5.0
Knowing why something failed A few codes on connection, a plain failure on subscription A reason code on every acknowledgement, and the server can explain a disconnection
Attaching metadata In the payload, by convention User properties, free-form key-value pairs
Resuming after a dropout Session kept or discarded, with no time limit Session expiry interval chosen by the device
Avoiding stale messages No provision Per-message expiry interval
Saving bytes Topic name repeated on every send Topic alias: a number replaces the name
Sharing the load on the server side Broker-specific extensions Shared subscriptions, in the standard

Each of these rows addresses a real annoyance. Reason codes turn a silence into a diagnosis, since the device can write in its log that it was not authorised rather than merely note that “nothing happens”. Session expiry lets a device on a cellular network get its subscriptions back after a short dropout, without forcing the server to keep the state of a vanished device indefinitely. The topic alias matters as soon as every byte sent costs energy. As for shared subscriptions, they let several programs on the server side split the same stream of messages between them, each receiving only a share. The standard also adds a request/response mechanism, with a response topic and correlation data, which saves reinventing it in every project.

What we chose: the stack on the microcontroller

Our board, the Walter, combines an ESP32-S3 microcontroller and an LTE-M cellular modem. We discuss it in the article we devoted to it. It offers two ways of speaking MQTT. The first delegates the protocol to the modem, which handles it on its own while the microcontroller sleeps. The second runs MQTT and TLS encryption in the firmware of the ESP32-S3, the modem then serving only as a pipe for the data.

On 2 May 2026, we recorded the second as our choice. The reason written down at the time is twofold: we had no assurance that the modem would speak MQTT 5, and we did not control the cipher suites it would negotiate. On the microcontroller, Espressif’s ESP-MQTT library supports version 5, and the encryption settings are ours to choose. We had noted the cost as well: of the order of 50 to 100 kilobytes of RAM, and higher power consumption since the microcontroller has to stay awake. We have not measured this second point.

We wrote the test program the same day. A Walter board was to connect to the broker using MQTT 5, over Wi-Fi and TLS, publish its status with user properties, request topic aliases and write the reason codes received to its console. For want of a recorded result, we do not count it among our successful tests. It was a lab test in any case, over Wi-Fi and not over the cellular network. In July, we wrote another test bench to publish in the same way what the board heard over Bluetooth, and it had yet to be run on a board.

The plan for another broker, and why it remained a plan

Our broker is Mosquitto, open-source software from the Eclipse Foundation that has supported MQTT 5 since version 1.6. So the protocol was not the problem. What bothered us, according to our notes from the time, was everything around it: a single node, access rights described in a static file and no structured audit log.

We then wrote a six-phase plan to move to EMQX, a more fully featured broker. The plan was blunt about what held us back. The choice sat uneasily with our preference for open-source, European software, all the more so since the vendor has announced that the software was moving to the BSL 1.1 licence from version 5.9. This is a so-called “source-available” licence, which restricts certain uses. We were willing to accept it for a demonstrator, and no further. We had noted two other candidates: HiveMQ Community Edition, under the Apache 2 licence, and VerneMQ, also open source.

The rule we are keeping

Out of this hesitation came the rule we are keeping: use only the MQTT 5 features that are in the standard, and no broker-specific extensions. A communication contract written that way is portable from one server to another, and that is probably the most lasting benefit of the whole episode.

Where we stand.

The broker in service is still Mosquitto. We never began the migration to EMQX: the files were ready, then the project changed direction. Since July 2026, the Cube has decided on the spot, with no network, as we describe in another article. So the MQTT 5 test on the Walter board remains frozen, and its follow-up over the cellular network never happened. MQTT 5 remains our communication contract for connected Cubes, as a design target. We did plan a move; we just never packed the boxes.

Sources

A question, an objection? contact@ops-devices.eu, or on Bluesky.