Skip to content

feat(sensing-server): EventBus + MQTT bridge for Home Assistant#486

Open
schwarztim wants to merge 3 commits intoruvnet:mainfrom
schwarztim:pr/mqtt-home-assistant-bridge
Open

feat(sensing-server): EventBus + MQTT bridge for Home Assistant#486
schwarztim wants to merge 3 commits intoruvnet:mainfrom
schwarztim:pr/mqtt-home-assistant-bridge

Conversation

@schwarztim
Copy link
Copy Markdown

Motivation

RuView deployments need to publish sensing events (presence, body tracking, zones, vitals) to home-automation systems. MQTT is the de-facto protocol for Home Assistant, Node-RED, openHAB, and others. This PR adds two coupled pieces:

  1. EventBus (event_stream.rs) — an in-process pub-sub built on tokio::sync::broadcast with a typed Event enum covering presence, body, zone, and vital-sign events.
  2. MQTT bridge (mqtt_bridge.rs) — opt-in tokio task subscribing to the EventBus and publishing to MQTT topics under a configurable prefix.

Why bundled into one PR?

The MQTT bridge depends on the EventBus to source events. EventBus was net-new in this fork and is not yet present in upstream's v2/. Splitting into two PRs would require shipping the EventBus first as a no-op (no consumer), which is harder to review and provides no immediate value. Keeping them together produces a complete, testable feature.

Changes

  • NEW: v2/crates/wifi-densepose-sensing-server/src/event_stream.rs (+288 LOC) — EventBus, Event enum, EventSubscriber helper
  • NEW: v2/crates/wifi-densepose-sensing-server/src/mqtt_bridge.rs (+212 LOC) — MqttBridge task using rumqttc
  • v2/crates/wifi-densepose-sensing-server/src/main.rs (+19 LOC) — mod declarations + instantiate EventBus at startup; spawn MqttBridge if MQTT_URL is set; add mqtt_url field to Args
  • v2/crates/wifi-densepose-sensing-server/src/cli.rs (+4 LOC) — mqtt_url field in public Args struct
  • v2/Cargo.toml + crate Cargo.toml — add rumqttc workspace dependency

Configuration

  • SENSING_MQTT_URL / --mqtt-url (required to enable, e.g. mqtt://broker.local:1883)
  • MQTT_TOPIC_PREFIX (default ruview/)
  • MQTT_USERNAME / MQTT_PASSWORD (optional)

Test fixture URL is mqtt://test.example.com:1883 — no real IPs.

Test results

  • cargo test --workspace --no-default-features: 1639 passed, 0 failed (4 new unit tests in mqtt_bridge)
  • python v1/data/proof/verify.py: VERDICT: FAIL — pre-existing, also fails on unmodified origin/main (numpy/scipy version drift); not caused by this PR

Notes

  • Opt-in: bridge dormant unless --mqtt-url / SENSING_MQTT_URL is set. Zero impact on existing deployments.
  • EventBus is also useful as a foundation for future webhook/SSE/REST stream APIs.
  • No new ADR — follows existing module patterns. Could be referenced as the "event-bus + integration bridge" pattern in a future design doc.

Deploy Bot added 3 commits April 28, 2026 13:17
Add missing mod declarations (mod event_stream, mod mqtt_bridge) and
mqtt_url field to the Args struct so the MQTT bridge introduced in the
previous commit compiles. Cargo.lock updated with rumqttc resolution.
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.

1 participant