Skip to content

Add MQTT v5 protocol version support - #562

Draft
Apollon77 with Copilot wants to merge 6 commits into
masterfrom
copilot/add-mqtt-v5-support
Draft

Add MQTT v5 protocol version support#562
Apollon77 with Copilot wants to merge 6 commits into
masterfrom
copilot/add-mqtt-v5-support

Conversation

Copilot AI commented Oct 17, 2025

Copy link
Copy Markdown
Contributor

Overview

This PR adds support for MQTT v5 (protocol version 5) while maintaining full backward compatibility with the existing MQTT v3.1.1 (protocol version 4) implementation.

Closes #[issue number]

Problem

The adapter was hard-coded to use MQTT v3.1.1 (protocol version 4), preventing users from taking advantage of MQTT v5 features such as:

  • Enhanced authentication mechanisms
  • Request/response patterns
  • User properties
  • Message expiry intervals
  • Topic aliases
  • Reason codes and better error handling

Reference:

protocolVersion: 4,

Solution

Added a configurable protocolVersion option that allows users to select between MQTT v3.1.1 and MQTT v5:

Admin UI Configuration

  • Added new "Protocol settings" section in the admin interface
  • Dropdown selector with two options:
    • MQTT v3.1.1 (default) - Protocol version 4
    • MQTT v5 - Protocol version 5
  • Translations provided for all 11 supported languages

Client Mode

The adapter's MQTT client now respects the configured protocol version when connecting to external brokers:

const opts = {
    clientId: clientId,
    protocolId: 'MQTT',
    protocolVersion: config.protocolVersion || 4, /* default to v3.1.1 */
    // ... other options
};

Server Mode

The adapter's MQTT broker automatically supports both protocol versions simultaneously. The mqtt-connection library handles protocol negotiation automatically based on each client's connection request, so no configuration is needed - the server accepts both MQTT v3.1.1 and v5 clients out of the box.

Security Checker

The public IP accessibility checker now uses the configured protocol version to ensure security checks work correctly with both protocol versions.

Technical Details

  • Libraries: Both mqtt (v5.14.1) and mqtt-connection (v4.1.0) fully support MQTT v5
  • Default Behavior: Protocol version 4 (MQTT v3.1.1) when not configured
  • Backward Compatible: Existing installations continue working without any configuration changes

Testing

  • Added 2 new tests in test/testProtocolVersion.js to verify protocol version configuration
  • All 39 tests pass (37 existing + 2 new)
  • Verified backward compatibility with default settings
  • Confirmed both client and server modes work correctly

Files Changed

  • admin/jsonConfig.json - Added protocol version selector
  • admin/i18n/*.json - Added translations (11 languages)
  • lib/client.js - Use configurable protocol version
  • lib/server.js - Added documentation comment
  • lib/securityChecker.js - Accept protocol version parameter
  • main.js - Pass protocol version to security checker
  • test/testProtocolVersion.js - New tests for protocol version functionality

Migration

No migration needed - the adapter defaults to MQTT v3.1.1 (protocol version 4) for backward compatibility. Users who want to use MQTT v5 can simply select it in the adapter configuration.

Original prompt

This section details on the original issue you should resolve

<issue_title>MQTT v5 support</issue_title>
<issue_description>I see the current implementation hard codes to v3.1.1 (aka, confusingly, v4):

protocolVersion: 4,

Any plans to support MQTT v5?</issue_description>

<agent_instructions>Please check what would be needed to support v3.1.1 of mqtt and also v5 and propose changes and - if relevant - selection options for the users</agent_instructions>

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

@Apollon77 Would be an enhancement and check what effects such an upgrade would mean ...

Fixes #487


✨ 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 5 commits October 17, 2025 08:25
Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for MQTT v5 in implementation Add MQTT v5 protocol version support Oct 17, 2025
Copilot AI requested a review from Apollon77 October 17, 2025 08:44
@Gizimo Gizimo mentioned this pull request Jun 17, 2026
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.

MQTT v5 support

2 participants