AI-powered wearable health monitoring system using Raspberry Pi, MAX30100 biometric sensor, and Deepseek AI for intelligent sleep analysis, stress detection, and fatigue monitoring.
- Smart Wake-up - Wake during light sleep for better mornings
- Sleep Stage Detection - Local + AI-powered analysis
- Stress Monitoring - Real-time stress level assessment
- Fatigue Detection - Job performance and safety monitoring
- AI Call Monitoring - Track all AI interactions
- Web Dashboard - Pairing, settings, and AI analytics
Hardware:
- Raspberry Pi Zero/4
- MAX30100 sensor (heart rate, SpO2)
- 2x WS2812B RGB LEDs (NeoPixel)
- Push button
Software:
- Flask REST API (Python)
- MySQL database
- Deepseek AI (v3.2 685B)
- Local sleep detection on device
Data Flow:
Device → Collect Sensor Data (5s intervals)
→ Local Sleep Detection
→ Create Enriched CSV (every 10 min)
→ Upload to Server
Server → Store in Database
→ AI Analysis on Request
→ Log AI Calls
→ Return Results to Device
curl -X POST http://localhost:5000/api/device/register \
-H "Content-Type: application/json" \
-d '{"mac_address": "AA:BB:CC:DD:EE:FF"}'curl -X POST http://localhost:5000/api/device/AA:BB:CC:DD:EE:FF/data \
-H "Content-Type: text/csv" \
--data-binary @sensor_data.csvCSV Format (9 fields):
timestamp,heart_rate,spo2,sleep_stage,hrv_rmssd_ms,baseline_hr,baseline_deviation_pct,hr_std_dev,mean_hr
curl "http://localhost:5000/api/device/AA:BB:CC:DD:EE:FF/data?start_date=2026-01-25T00:00:00&end_date=2026-01-25T23:59:59"curl http://localhost:5000/api/device/AA:BB:CC:DD:EE:FFcurl http://localhost:5000/api/device/AA:BB:CC:DD:EE:FF/settingscurl http://localhost:5000/api/devices/curl -X POST http://localhost:5000/api/pairing/request \
-H "Content-Type: application/json" \
-d '{"mac_address": "AA:BB:CC:DD:EE:FF"}'curl -X POST http://localhost:5000/api/pairing/verify \
-H "Content-Type: application/json" \
-d '{"code": "[\"red\",\"blue\"]"}'curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/sleep-stage?minutes=10"curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/sleep-stage?use_local=true"curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/stress?minutes=5"curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/fatigue?minutes=5"curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/performance?minutes=5"curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/optimal-wakeup"curl "http://localhost:5000/api/ai-logs?hours=24&endpoint=performance&mac_address=AA:BB:CC:DD:EE:FF&success_only=false&limit=100"Query Parameters:
hours- Time window (default: 24)endpoint- Filter: sleep_stage, stress, fatigue, performancemac_address- Filter by devicesuccess_only- true/falselimit- Max results (default: 100)
curl "http://localhost:5000/api/ai-logs/stats?hours=24"curl http://localhost:5000/api/ai-logs/123http://localhost:5000/
http://localhost:5000/pair
http://localhost:5000/settings
http://localhost:5000/ai-monitor
# 1. Register device
curl -X POST http://localhost:5000/api/device/register \
-H "Content-Type: application/json" \
-d '{"mac_address": "AA:BB:CC:DD:EE:FF"}'
# 2. Create sample data
cat > sample_data.csv << 'EOF'
timestamp,heart_rate,spo2,sleep_stage,hrv_rmssd_ms,baseline_hr,baseline_deviation_pct,hr_std_dev,mean_hr
2026-01-25T06:00:00Z,72,98,light_sleep,45.2,75,-4.0,3.2,71.5
2026-01-25T06:00:05Z,71,98,light_sleep,42.8,75,-5.3,3.1,71.2
2026-01-25T06:00:10Z,70,97,deep_sleep,38.5,75,-6.7,2.8,70.8
EOF
# 3. Upload data
curl -X POST http://localhost:5000/api/device/AA:BB:CC:DD:EE:FF/data \
-H "Content-Type: text/csv" \
--data-binary @sample_data.csv
# 4. Test local sleep detection
curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/sleep-stage?use_local=true"
# 5. Test AI sleep analysis
curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/sleep-stage?minutes=10"
# 6. Test stress
curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/stress?minutes=5"
# 7. Test fatigue
curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/fatigue?minutes=5"
# 8. Test combined performance
curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/performance?minutes=5"
# 9. View AI statistics
curl "http://localhost:5000/api/ai-logs/stats?hours=24"cd webserver
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
flask db upgrade
python app.pycd wrclient
pip3 install -r requirements.txt
sudo ./venv/bin/python3 app.py --mac AA:BB:CC:DD:EE:FF --server http://***:***:***:***:5000