ContextLab / ContextLab/dream-stream

Build WearOS and watchOS companion apps for sleep stage detection

Open
#118 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
4
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## Summary
Build native companion apps for WearOS and watchOS that run during sleep sessions to provide real-time accelerometer data and optimized vitals streaming for improved sleep stage classification.

## Background
Currently we rely on Health Connect/HealthKit for sleep data, which has limitations:
- **HRV data** - Fitbit doesn't sync HRV to Health Connect
- **Movement detection** - No accelerometer access through Health Connect
- **Data latency** - Health data is synced periodically, not real-time
- **Time alignment** - HR samples often don't overlap with sleep stage windows

## Proposed Solution

### WearOS Companion App
- **Platform**: Kotlin, Jetpack Compose for Wear OS
- **Sensors**: Accelerometer (10Hz), Heart Rate (continuous), HRV if available
- **Communication**: DataClient/MessageClient API to phone app
- **Battery**: Foreground service with wake lock, optimized sampling

### watchOS Companion App
- **Platform**: Swift, SwiftUI
- **Sensors**: Accelerometer, Heart Rate via HealthKit workout session
- **Communication**: WatchConnectivity framework
- **Battery**: Extended runtime session for sleep tracking

### Data Protocol
```typescript
interface WatchData {
timestamp: number;
heartRate?: number;
hrvMs?: number;
accelerometer?: { x: number; y: number; z: number };
movementIntensity?: number; // computed on-watch to reduce bandwidth
}
```

### Features
1. **Real-time streaming** during active sleep sessions
2. **On-watch movement computation** to reduce data transfer
3. **Local buffering** if phone connection lost
4. **Battery-efficient sampling** (reduce accelerometer rate during low-movement periods)
5. **Sleep stage inference on watch** as fallback

## Implementation Phases

### Phase 1: WearOS MVP
- [ ] Basic foreground service with accelerometer sampling
- [ ] Heart rate continuous monitoring
- [ ] DataClient communication to phone
- [ ] Phone-side receiver and integration with sleep.ts

### Phase 2: watchOS MVP
- [ ] HealthKit workout session for extended runtime
- [ ] WatchConnectivity message passing
- [ ] Phone-side receiver for iOS

### Phase 3: Optimization
- [ ] On-device movement intensity computation
- [ ] Adaptive sampling rates
- [ ] Battery usage optimization
- [ ] Offline buffering and sync

## Acceptance Criteria
- [ ] Watch app runs reliably for 8+ hour sleep session
- [ ] Movement data available within 1 second of occurrence
- [ ] Battery drain < 15% overnight on watch
- [ ] Improved sleep stage classification accuracy vs Health Connect alone

## Technical Notes
- WearOS: Use `SensorManager` for accelerometer, `HealthServicesClient` for HR
- watchOS: Use `CMMotionManager` for accelerometer, `HKWorkoutSession` for HR
- Consider using Protocol Buffers for efficient data serialization

## Related
- Improves sleep stage classification accuracy
- Enables movement-based awake detection
- Provides HRV data that Fitbit doesn't sync to Health Connect

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.