Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: mqtt: Add MQTT 5.0 support #87354

Merged
merged 18 commits into from
Mar 26, 2025
Merged

Conversation

rlubos
Copy link
Contributor

@rlubos rlubos commented Mar 19, 2025

Add MQTT 5.0 support and some basic tests. MQTT 5.0 support should mostly be transparent for MQTT 3.1.1 users (even if the Kconfig option is enabled), however one stable API change was required, which was reflected in the migration guide.

Resolves #21633

@zephyrbot zephyrbot added Release Notes To be mentioned in the release notes area: Networking area: Samples Samples area: Shell Shell subsystem labels Mar 19, 2025
@rlubos rlubos mentioned this pull request Mar 19, 2025
@rlubos rlubos force-pushed the net/mqtt-5 branch 2 times, most recently from 7c18434 to 0ab24bc Compare March 19, 2025 18:43
@kartben kartben assigned rlubos and jukkar and unassigned kartben Mar 22, 2025
rlubos added 4 commits March 25, 2025 10:42
It should be possible to select maximum supported MQTT version, so that
for example MQTT 5.0 features can be compiled-out in case they're not
needed.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add test variant which enables MQTT 5.0 support. MQTT 3.1.1 should still
work just fine in such case, so it needs to be verified that's the case.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
The macro did not take into account the 2-byte binary data length
encoded before the actual binary data.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add support for CONNECT message specified in MQTT 5.0, along with
property encoders required to encode MQTT properties which is a new
concept in MQTT 5.0. Connect and will properties can be specified by the
application in the mqtt_client structure before connecting.

Introduce a helper function which allows to verify whether MQTT 5.0 is
used or not, so that it's still possible to use MQTT 3.1 even if MQTT
5.0 support is enabled in Kconfig.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
@rlubos
Copy link
Contributor Author

rlubos commented Mar 25, 2025

Updated docstrings & rebased to resolve conflict.

jukkar
jukkar previously approved these changes Mar 25, 2025
Copy link
Collaborator

@pdgendt pdgendt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a full review yet, some early comments.

@rlubos
Copy link
Contributor Author

rlubos commented Mar 25, 2025

Thanks @pdgendt, I've addressed the initial nits, waiting for more :)

pdgendt
pdgendt previously approved these changes Mar 25, 2025
Copy link
Collaborator

@pdgendt pdgendt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More nits :)
Only have some bare minimum experience with MQTT, but the PR looks complete with extensive testing, and it is marked as experimental.

rlubos added 14 commits March 25, 2025 19:33
Add support for CONNACK message specified in MQTT 5.0, along with
property decoders required to decode MQTT properties. Decoded properties
are provided to the application within mqtt_connack_param structure,
accompanying the CONNACK event.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add support for PUBLISH message specified in MQTT 5.0. The message
encoder and decoder were updated to support MQTT properties.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add support for PUBACK, PUBREC, PUBREL and PUBCOMP specified in MQTT
5.0. As all of these acknowledgment packets have similar format,
introduced a common encoder/decoder to handle ACK packets.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add support for SUBSCRIBE/UNSUBSCRIBE messages specified in MQTT 5.0.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add support for SUBACK/UNSUBACK messaged specified in MQTT 5.0.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add support for DICONNECT message specified in MQTT 5.0.
As with MQTT 5.0, the disconnect can now also be initiated by the
broker, it was needed to add decoder support for the message.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add support for a new AUTH message introduced in MQTT 5.0.
This is a new mechanism specified by MQTT 5.0, which allows clients and
brokers for enhanced authentication in between CONNECT and CONNACK
exchange. An additional MQTT event (MQTT_EVT_AUTH) was specified which
is triggered when the AUTH packet arrives from the broker.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add support for handling topic aliases received from the broker.
The MQTT client implementation will store received topic for further use
in case consecutive PUBLISH received from the broker contains no topic
but alias only.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
As MQTT 5.0 allows to specify the disconnect reason in the Disconnect
packet, use this new feature to improve error notification to the
broker, according to the error guidelines in the MQTT 5.0 spec.
For most cases, a generic arbitrary mapping between errno values and
reason codes is used, however the parser can specify the disconnect
reason code manually to better handle certain corner cases (like invalid
topic alias used).

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add new test suite covering MQTT 5.0 packet format.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Make sure conditionally compiled parts of the public header related to
MQTT 5.0 support are rendered by doxygen.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Update migration guide for 4.2 release with an entry about the API
change related to MQTT 5.0 support.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add bullet for 4.2 release notes about MQTT 5.0 support.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
MQTT 5.0 is now supported so reflect this in the library documentation.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
@kartben kartben merged commit e380473 into zephyrproject-rtos:main Mar 26, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Networking area: Samples Samples area: Shell Shell subsystem Release Notes To be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for MQTT 5
5 participants