Skip to content

fix: make WebSocket path configurable for EMQX compatibility#307

Open
bplein wants to merge 3 commits into
meshcore-dev:mainfrom
bplein:fix/websocket-path-config
Open

fix: make WebSocket path configurable for EMQX compatibility#307
bplein wants to merge 3 commits into
meshcore-dev:mainfrom
bplein:fix/websocket-path-config

Conversation

@bplein

@bplein bplein commented Jul 10, 2026

Copy link
Copy Markdown

Summary

  • Fixes WebSocket connection failures with EMQX broker, which serves MQTT over WebSocket at /mqtt instead of /
  • Adds a new ws_path broker config option (default: / for backwards compatibility)
  • Existing configs default to / on next save, maintaining compatibility with most broker deployments.
  • Allows users of different brokers to customize the MQTT path if needed

Context

The hardcoded ws_set_options(path="/", ...) caused the Home Assistant integration to fail when connecting to EMQX, which expects WebSocket connections at the /mqtt path. This is the default WebSocket
endpoint for EMQX deployments.

Changes

  • mqtt_uploader.py: Added ws_path field to BrokerConfig with default /
  • mqtt_uploader.py: Pass ws_path from broker settings when creating BrokerConfig
  • mqtt_uploader.py: Use broker.ws_path instead of hardcoded / in ws_set_options
  • config_flow.py: Added ws_path field to broker config UI form
  • config_flow.py: Persist ws_path value when saving broker configuration

Testing

  • Verified against EMQX 6.2.0 with WebSocket at /mqtt
  • Backward compatible — existing configs without ws_path default to /
  • Users can override to any path via the HA integration config UI
  • Note: Not yet tested with non-EMQX brokers — please test with your broker and report any issues

Admission of Guilt

  • I used Claude to develop this fix, but I do understand the relatively minor changes made to the code.
  • I have not tested it against other popular brokers.

The hardcoded path "/" caused WebSocket handshakes to fail with EMQX,
which serves MQTT over WebSocket at /mqtt. Add a ws_path config option
(defaulting to /mqtt) so the integration works with both EMQX and
broker deployments that use a different WebSocket path.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Comment thread custom_components/meshcore/config_flow.py Outdated
client_id_prefix: str
topic_status: str
topic_packets: str
ws_path: str = "/mqtt"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The existing default was / and this changes the new default to /mqtt. It might make sense to change the default to / unless we know that /mqtt is what most users are already using.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That does make sense. I’ll make the change today.

@bplein bplein Jul 10, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

There were additional places where this incorrect default was set. Fixed and tested with 4f79a85

bplein and others added 2 commits July 10, 2026 07:07
Co-authored-by: Andy Shinn <andys@andyshinn.as>
Initial commits defaulted to /mqtt, these revert it to default to / which is the old behavior.
@bplein
bplein marked this pull request as draft July 10, 2026 15:57
@bplein

bplein commented Jul 10, 2026

Copy link
Copy Markdown
Author

Converted to draft, unexpected issue I need to resolve on my end (may not be related to the PR itself)

@bplein

bplein commented Jul 10, 2026

Copy link
Copy Markdown
Author

Errors were configuration issues on EMQX.

@bplein
bplein marked this pull request as ready for review July 10, 2026 17:37
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.

2 participants