Skip to content

feat(mqtt): standalone MQTT exporter, auto-discovery, and live workout streaming (#14) - #147

Open
foureight84 wants to merge 2 commits into
fix/batch-2026-11-12from
feat/14-mqtt
Open

foureight84 wants to merge 2 commits into
fix/batch-2026-11-12from
feat/14-mqtt

Conversation

@foureight84

Copy link
Copy Markdown
Owner

Closes #14
(Stacked on #144 / fix/batch-2026-11-12 for EN/RU string resources and worker hooks)

Summary

Adds a standalone, broker-agnostic MQTT 3.1.1 exporter (Settings → MQTT) for pushing ring health metrics, sleep sessions, daily activity, and live workout / spot measurements to any MQTT broker (Mosquitto, EMQX, HiveMQ, etc.), with consolidated JSON state topics and retained MQTT auto-discovery config publishing.

Key Features

  • Pure-Kotlin MQTT 3.1.1 client & session pool (MqttProtocol, MqttClient, MqttSessionPool):
    • Zero new third-party dependencies (Socket / SSLSocket with "HTTPS" hostname verification, QoS 0 & QoS 1 PUBLISH/PUBACK, PINGREQ/PINGRESP, 30 s idle connection pooling).
    • Broker password stored in EncryptedSharedPreferences (pulseloop_secure); settings persisted in pulseloop_prefs (pulseloop.mqtt.v1).
  • Configurable Sync Cadence & Live Streaming:
    • Background sync interval selector (15 / 30 / 60 / 120 min, clamped 15–720 min) wired into RingSyncWorker and ScheduledSpo2Worker (plus debounced MqttExportWorker after ring syncs and spot measurements).
    • Live workout & spot measurement streaming (MqttLivePublisher): coalesces rapid updates to ~5 s over a persistent pooled socket and triggers an immediate full snapshot when a workout ends.
  • Capability-Gated Sensors & Multi-Ring Identity:
    • Publishes up to 26 sensors per ring (battery, heart_rate, resting_heart_rate, spo2, hrv, stress gated by real hardware support #67, temperature, blood_pressure_systolic, blood_pressure_diastolic, blood_sugar, respiratory_rate gated by #103, vo2_max, steps, calories, distance, active_minutes, sleep_duration, sleep_score, sleep_deep, sleep_light, sleep_rem, sleep_awake, workout_active, workout_type, workout_duration, last_sync), with per-sensor toggles in Settings → MQTT.
    • Device-scoped state topics (<base_topic>/<device_slug>/state) and retained auto-discovery configs (<discovery_prefix>/<component>/pulseloop_<mac_or_id_hex>/<sensor_key>/config).
    • Strictly queries real hardware rows (source NOT IN ('demo', 'mock')).
  • UI, Localization & Docs:
    • Settings → MQTT screen with Test Connection, Publish Now, and Clear Retained Topics.
    • Full English and Russian (values-ru/strings.xml) localization.
    • Documentation in docs/mqtt.md.

Verification

  • Unit tests: MqttProtocolTest (18), MqttDiscoveryTest (13), MqttPrefsStoreTest (8) + full :app:testDebugUnitTest suite (1,753 passed, 0 failures).
  • Live broker integration tests (LiveMosquittoBrokerTest) against Eclipse Mosquitto 2.1.2 (publish, retained discovery, clear retained topics, and username/password CONNACK auth).
  • End-to-end Android Emulator verification (Settings → MQTT → Test Connection, Publish Now, and Clear Retained Topics verified via mosquitto_sub).

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