Skip to content

feat(mqtt): add MQTT exporter, Home Assistant auto-discovery, and live streaming - #148

Open
foureight84 wants to merge 2 commits into
saksham2001:mainfrom
foureight84:feat/mqtt-export
Open

foureight84 wants to merge 2 commits into
saksham2001:mainfrom
foureight84:feat/mqtt-export

Conversation

@foureight84

@foureight84 foureight84 commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Ports the standalone MQTT 3.1.1 integration from PulseLoopAndroid (PR #147) to iOS.

Summary

  • MQTT 3.1.1 wire protocol (MqttProtocol.swift): Pure-Swift encoder/decoder for CONNECT, CONNACK, PUBLISH (QoS 0/1, retain/dup), PUBACK, PINGREQ/PINGRESP, and DISCONNECT.
  • Native Network.framework transport (MqttClient.swift): NWConnection-backed client supporting TCP, TLS (mqtts://), and WebSocket (ws:// / wss://, including IPv6 literals) with task-cancellation safety, plus a serialized MqttSessionPool with stale-socket retry for live streaming.
  • Settings & Keychain (MqttPrefsStore.swift, MqttSettingsView.swift): Stores broker preferences in UserDefaults and the broker password in Keychain (com.pulseloop.mqtt), wired into Settings → Resources → MQTT (AppRoute.settingsMqtt).
  • Home Assistant auto-discovery & state payloads (MqttDiscovery.swift): Capability- and data-gated sensor descriptors (including binary_sensor for active workouts and hardware-only gating for stress/respiratory rate/VO2max), removal tombstones for stale sensors, and JSON state payloads.
  • Snapshot collector & publisher (MqttExporter.swift, MqttSyncPublisher.swift, PulseLoopApp.swift): Reads real (non-demo/mock) SwiftData metrics via bounded per-kind queries and publishes off PulseDataChange.shared.token and scenePhase edges (~5 s live debounce or configurable 15–720 min periodic interval).

Verification

  • xcodebuild test -project PulseLoop.xcodeproj -scheme PulseLoop -destination 'platform=iOS Simulator,name=iPhone 17' -only-testing:PulseLoopTests/MqttProtocolTests -only-testing:PulseLoopTests/MqttDiscoveryTests -only-testing:PulseLoopTests/MqttPrefsStoreTests -only-testing:PulseLoopTests/MqttExporterTests — 15/15 tests passed.

…e streaming

Port Android PR saksham2001#147's standalone MQTT 3.1.1 integration to iOS:
- Pure-Swift MQTT 3.1.1 wire protocol (CONNECT, CONNACK, PUBLISH QoS 0/1, PUBACK, PINGREQ/PINGRESP, DISCONNECT) with unit tests.
- Native Network.framework (NWConnection) client supporting TCP, TLS (mqtts://), and WebSocket (ws:// / wss://) with a serialized session pool and stale-socket retry.
- Keychain-backed broker password storage (MqttPrefsStore) and UserDefaults prefs.
- Home Assistant auto-discovery and capability/data-gated state payloads (MqttDiscovery).
- SwiftData snapshot collector (MqttExporter) and coalesced live/periodic publisher (MqttSyncPublisher).
- Settings -> MQTT configuration screen (MqttSettingsView).

This branch has not been deployed

No deployments
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