Skip to content

GraemeIBB/TNHackathon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TNHackathon: Health Monitoring & Smart Wake-up System

AI-powered wearable health monitoring system using Raspberry Pi, MAX30100 biometric sensor, and Deepseek AI for intelligent sleep analysis, stress detection, and fatigue monitoring.

Features

  • 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

Architecture

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

API Endpoints

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. Upload Sensor Data

curl -X POST http://localhost:5000/api/device/AA:BB:CC:DD:EE:FF/data \
  -H "Content-Type: text/csv" \
  --data-binary @sensor_data.csv

CSV Format (9 fields):

timestamp,heart_rate,spo2,sleep_stage,hrv_rmssd_ms,baseline_hr,baseline_deviation_pct,hr_std_dev,mean_hr

3. Get Device Data

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"

4. Get Device Info

curl http://localhost:5000/api/device/AA:BB:CC:DD:EE:FF

5. Get Device Settings

curl http://localhost:5000/api/device/AA:BB:CC:DD:EE:FF/settings

6. List All Devices

curl http://localhost:5000/api/devices/

7. Request Pairing Code

curl -X POST http://localhost:5000/api/pairing/request \
  -H "Content-Type: application/json" \
  -d '{"mac_address": "AA:BB:CC:DD:EE:FF"}'

8. Verify Pairing Code

curl -X POST http://localhost:5000/api/pairing/verify \
  -H "Content-Type: application/json" \
  -d '{"code": "[\"red\",\"blue\"]"}'

9. Sleep Stage Detection (AI Analysis)

curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/sleep-stage?minutes=10"

10. Sleep Stage Detection (Local - No AI Call)

curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/sleep-stage?use_local=true"

11. Stress Level Analysis

curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/stress?minutes=5"

12. Fatigue Level Analysis

curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/fatigue?minutes=5"

13. Performance Metrics (Combined Stress + Fatigue - Single AI Call)

curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/performance?minutes=5"

14. Optimal Wake-up Time (Uses Local Detection - No AI Call)

curl "http://localhost:5000/api/analysis/AA:BB:CC:DD:EE:FF/optimal-wakeup"

15. Get AI Call Logs

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, performance
  • mac_address - Filter by device
  • success_only - true/false
  • limit - Max results (default: 100)

16. Get AI Usage Statistics

curl "http://localhost:5000/api/ai-logs/stats?hours=24"

17. Get Specific AI Call Details

curl http://localhost:5000/api/ai-logs/123

Web UI Pages

Home Page

http://localhost:5000/

Pairing Page

http://localhost:5000/pair

Settings Page

http://localhost:5000/settings

AI Monitor Dashboard

http://localhost:5000/ai-monitor

Complete Test Flow

# 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"

Setup

Server

cd webserver
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
flask db upgrade
python app.py

Client (Raspberry Pi)

cd wrclient
pip3 install -r requirements.txt
sudo ./venv/bin/python3 app.py --mac AA:BB:CC:DD:EE:FF --server http://***:***:***:***:5000

About

Our submission to the TelusXTechnation 2026 hackathon.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors