8000 feat(sensors): reach the MQTT hub through remote access, over WebSockets at /mqtt by adeelahmad · Pull Request #508 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content

feat(sensors): reach the MQTT hub through remote access, over WebSockets at /mqtt - #508

Merged
adeelahmad merged 10 commits into
mainfrom
claude/project-thread-ppx7di
Oct 18, 2026
Merged

adeelahmad merged 10 commits into
mainfrom
claude/project-thread-ppx7di

Conversation

@adeelahmad
Copy link
Copy Markdown
Owner

Description

Before: Remote access (the Cloudflare tunnel) and HTTPS reached only the web app, so the sensor hub's MQTT broker on port 1883 was out of reach for a phone or a sensor away from home.

After: with MQTT at the web app's address too on in Settings › Sensors (off by default), devices anywhere publish and subscribe at wss://<your address>/mqtt, the same broker as port 1883. Every client there signs in with a hub login (anonymous clients are refused even where 1883 allows them), and too many wrong passwords from one address are throttled like sign-in. Remote access now says what it reaches and why SMB, NFS and syslog stay on the local network.

How: the hub's broker also takes MQTT over WebSockets on port 9883 (sensors.mqtt_web_port), through the websockets library Lens already ships (the Slack connector uses it too), and lens-relay.js, which already relays /s3 and /dav (#402), passes /mqtt upgrades to it with the visitor's address, so throttles see the real client. The compose files point the web app at http://worker:9883.

Motivation and Context

The owner asked whether remote access reaches S3, WebDAV, MCP and other protocols, and to add what it doesn't. S3 and WebDAV landed in #402; MCP already worked over HTTP. This adds MQTT, the remaining protocol that can travel over HTTP.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change; ! in the title)

Checklist:

  • The title is a Conventional Commit.
  • My code follows the code style of this project (make hooks checks it on commit).
  • I added or updated tests.
  • My change requires documentation updates, and I have updated docs/ accordingly.
  • Users need more than the title to understand it, so I wrote it under ## Unreleased in CHANGELOG.md.

Done questions (AGENTS.md)

  • Goal: remote access now reaches the MQTT hub as well as S3 and WebDAV (feat(shares): reach S3 and WebDAV through remote access, at /s3 and /dav #402); merged on green CI.
  • Agents: the setting is in the settings API (sensors.mqtt_web), and any MQTT client with a WebSocket transport connects.
  • Zero setup: the compose files carry LENS_MQTT_WS_URL; turning it on is one switch.
  • Fewest clicks: one switch; the sensors page shows the wss:// address next to the MQTT port.
  • Configurable: sensors.mqtt_web and sensors.mqtt_web_port in Settings › Sensors, with defaults (off, 9883).
  • Light: no new dependency; the listener runs only when the switch is on.
  • Private and secure: hub logins only, per-visitor throttle, off by default; threat model updated (entry point, P-THROTTLE).
  • Cost: n/a, no model calls.
  • User decides: off until an admin turns it on; existing defaults unchanged.
  • Upgrades: new settings default off; no stored-data change.
  • Honest: docs say exactly what remote access reaches and what stays local; README built list and docs/requirements.md row added (and feat(shares): reach S3 and WebDAV through remote access, at /s3 and /dav #402's In progress line moved to built).
  • Tests, docs and generated files updated (make openapi).
  • Open standards: MQTT over WebSockets (the MQTT spec's own WebSocket binding).
  • Result reported with evidence; refine later: per-topic access for hub logins.
  • Reuse: the hub's own broker, the websockets library already installed, and the lens-relay.js relay from feat(shares): reach S3 and WebDAV through remote access, at /s3 and /dav #402.

Local CI (ci/local-ci.sh): Next.js, pre-commit and PR title pass; the backend run caught a timing race in the new WebSocket test (a client count read before a closed client's goodbye arrived), now waited for and passing five runs in a row.


Generated by Claude Code

…ets at /mqtt

The broker also listens for MQTT over WebSockets (sensors.mqtt_web, off by
default; sensors.mqtt_web_port 9883) and the web app relays /mqtt to it,
upgrades included, so the Cloudflare tunnel and HTTPS reach the hub. There
every client signs in with a hub login (never anonymous) and failed logins
are throttled per visitor, read from X-Forwarded-For as trusted proxies
report it. Docs say why SMB, NFS and syslog stay on the local network.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CXpr1EWCfUD5tb1SmSwfDa
…-ppx7di

# Conflicts:
#	README.md
#	threat-model.md
#	threat-model.yaml
…-ppx7di

# Conflicts:
#	CHANGELOG.md
#	threat-model.yaml
…-ppx7di

# Conflicts:
#	CHANGELOG.md
#	threat-model.yaml
adeelahmad added a commit that referenced this pull request Oct 17, 2026
…525)

threat-model.yaml kept a sha256 of the whole prose, so any two pull requests
that changed threat-model.md both rewrote that one line and the second to merge
conflicted (#400, #508). The YAML's prose_version now names the prose in the
same commit, and the validator's new --base check (run by CI against the merge
commit's parent) fails a change to the prose that changes neither companion,
which is what the hash enforced, without a line every change edits. Adds tests,
including two branches that change the prose in different places merging
cleanly and still validating.

Fixes #507


Claude-Session: https://claude.ai/code/session_01Bwc5go44W4hjHKu329MepB

Co-authored-by: Adeel Ahmad <noreply@anthropic.com>
…-ppx7di

# Conflicts:
#	docs/requirements.md
#	threat-model.yaml
The merge of main took main's whole threat-model.yaml, dropping the
/mqtt entry point, the sensors.mqtt_web flag and P-SENSORS' conditions.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CXpr1EWCfUD5tb1SmSwfDa
@adeelahmad
adeelahmad merged commit a728ab7 into main Oct 18, 2026
21 checks passed
@adeelahmad
adeelahmad deleted the claude/project-thread-ppx7di branch October 18, 2026 01:06
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

0