Skip to content

Add basic MQTT 5.0 protocol support#805

Merged
ithewei merged 4 commits intomasterfrom
copilot/support-mqtt5-connection
Mar 10, 2026
Merged

Add basic MQTT 5.0 protocol support#805
ithewei merged 4 commits intomasterfrom
copilot/support-mqtt5-connection

Conversation

Copy link
Contributor

Copilot AI commented Mar 9, 2026

  • Update mqtt/mqtt_protocol.h: Fix typo in MQTT_PROTOCOL_V5 comment, add AUTH packet type (v5)
  • Update mqtt/mqtt_client.c: Add #include "hmath.h" for varint_decode, add helper to skip v5 properties
  • Update mqtt/mqtt_client.c mqtt_client_login(): Add empty MQTT v5 properties in CONNECT packet (Variable Header properties + Will properties)
  • Update mqtt/mqtt_client.c on_packet(): Skip v5 properties in CONNACK, PUBLISH, SUBACK, UNSUBACK parsing
  • Update mqtt/mqtt_client.c mqtt_client_publish(): Add empty v5 properties in PUBLISH packet
  • Update mqtt/mqtt_client.c mqtt_client_subscribe(): Add empty v5 properties in SUBSCRIBE packet
  • Update mqtt/mqtt_client.c mqtt_client_unsubscribe(): Add empty v5 properties in UNSUBSCRIBE packet
  • Update mqtt/mqtt_client.h: Add setProtocolVersion() method to C++ MqttClient class
  • Build and verify changes compile
  • Run code review and security checks
  • Fix CONNECT comment: will_properties uses varint prefix, not fixed 2-byte
Original prompt

This section details on the original issue you should resolve

<issue_title>请问支持mqtt5.0吗</issue_title>
<issue_description>请问支持mqtt5.0吗?</issue_description>

Comments on the Issue (you are @copilot in this section)

@ithewei 没有实现mqtt5.0的新特性,但是应该可以修改`mqtt_client_t`的`protocol_version`值,然后连接mqtt5.0服务,使用基本的发布/订阅功能。

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits March 9, 2026 03:46
- Add empty properties in CONNECT, PUBLISH, SUBSCRIBE, UNSUBSCRIBE packets
- Add will properties support in CONNECT packet for MQTT v5
- Skip v5 properties in CONNACK, PUBLISH, SUBACK, UNSUBACK responses
- Add mqtt_v5_skip_properties() helper for parsing v5 property sections
- Add AUTH packet type (type 15) to mqtt_type_e enum
- Add setProtocolVersion() method to C++ MqttClient class
- Include hmath.h for varint_decode used in property skipping

Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for MQTT 5.0 connection Add basic MQTT 5.0 protocol support Mar 9, 2026
@ithewei ithewei marked this pull request as ready for review March 10, 2026 12:51
Copilot AI review requested due to automatic review settings March 10, 2026 12:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds basic MQTT 5.0 framing compatibility to libhv’s MQTT client so it can interoperate with v5 brokers for simple CONNECT + publish/subscribe workflows by emitting empty Properties sections and skipping Properties on incoming packets.

Changes:

  • Add MQTT v5 packet framing support by appending empty Properties (varint length = 0) to CONNECT (incl. Will), PUBLISH, SUBSCRIBE, and UNSUBSCRIBE outbound packets.
  • Add inbound parsing support for MQTT v5 by skipping Properties on CONNACK/PUBLISH/SUBACK/UNSUBACK using a mqtt_v5_skip_properties() helper (based on varint_decode).
  • Update protocol definitions (MQTT v5 no longer marked unsupported; add MQTT_TYPE_AUTH) and expose MqttClient::setProtocolVersion() in the C++ wrapper.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
mqtt/mqtt_protocol.h Updates MQTT v5 protocol constants and adds MQTT_TYPE_AUTH.
mqtt/mqtt_client.h Adds C++ API to set protocol_version on the underlying C client.
mqtt/mqtt_client.c Implements minimal MQTT v5 properties framing (send empty properties; skip received properties).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* 2 + protocol_name + 1 protocol_version + 1 conn_flags + 2 keepalive +
* [v5: properties] +
* 2 + [client_id] +
* [v5: 2 + will_properties] + [2 + will_topic + 2 + will_payload] +
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The CONNECT format comment is inaccurate for MQTT v5: Will Properties are prefixed by a variable-byte integer property length (1–4 bytes), not a 2-byte length field. Consider updating the comment to avoid implying a fixed 2-byte prefix for will_properties.

Suggested change
* [v5: 2 + will_properties] + [2 + will_topic + 2 + will_payload] +
* [v5: varint + will_properties] + [2 + will_topic + 2 + will_payload] +

Copilot uses AI. Check for mistakes.
@ithewei
Copy link
Owner

ithewei commented Mar 10, 2026

@copilot apply changes based on the comments in this thread

Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 10, 2026

@copilot apply changes based on the comments in this thread

Fixed in 9d8b8b8 — updated the CONNECT packet format comment to use varint instead of 2 for the will_properties prefix, matching the MQTT v5 spec.

@ithewei ithewei merged commit 045fd61 into master Mar 10, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

请问支持mqtt5.0吗

3 participants