Skip to content

Siddiha/Airea

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

562 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Airea - AI-Powered Health Monitoring System

Intelligent Real-time Health Monitoring Using Edge AI & IoT

License: MIT Spring Boot Flutter ESP32 TensorFlow PostgreSQL


🎯 About The Project

Airea is a comprehensive AI-powered health monitoring system that leverages Edge AI, IoT sensors, and cloud computing to provide real-time health insights. The system monitors multiple health metrics including respiratory health (cough detection), heart rate, respiratory rate, body temperature, and fall detection with automatic emergency alerts.

Why Airea?

  • πŸ₯ Healthcare - Remote patient monitoring and chronic disease management
  • 🏠 Home Care - Non-invasive health surveillance for elderly and families
  • πŸ€– AI-Powered - Edge ML inference with TensorFlow Lite for real-time analysis
  • πŸ”’ Privacy-First - Sensor data processed locally on ESP32 device
  • πŸ“Š Comprehensive - Multiple health metrics in one wearable system
  • 🚨 Emergency Alerts - Automatic SMS alerts to emergency contacts

✨ Key Features

πŸ€– Edge AI Capabilities

  • βœ… On-device ML inference using TensorFlow Lite Micro
  • βœ… Real-time cough classification with confidence scoring (>80%)
  • βœ… Fall detection using accelerometer/gyroscope fusion
  • βœ… Low latency DSP-based heart rate and respiratory rate extraction
  • βœ… INT8 quantized models for ESP32 optimization

πŸ“Š Health Monitoring

  • 🫁 Respiratory - Cough detection via INMP441 microphone + CNN model
  • ❀️ Cardiovascular - Heart rate (BPM) via AD8232 ECG module with DSP peak detection
  • 🌬️ Breathing - Respiratory rate via ECG-derived respiration (EDR)
  • 🌑️ Temperature - Body temperature via MAX30205 sensor
  • πŸƒ Motion - Fall detection via MPU6050 IMU + G-force analysis

🚨 Emergency Alert System

  • Automatic SMS alerts via Notify.lk API
  • Critical thresholds: HR <40 or >150 BPM, Temp <35Β°C or >39.5Β°C, RR <8 or >30
  • Fall impact severity scoring (G-force >2.5G triggers alert)
  • GPS location included in emergency messages
  • 5-minute cooldown to prevent duplicate alerts

🌐 Cross-Platform

  • iOS, Android, Web, and Desktop support via Flutter
  • Real-time data synchronization with WebSocket
  • Daily/Weekly health summaries with AI-generated insights
  • Patient & Doctor role-based dashboards

πŸ—οΈ System Architecture

High-Level Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                            AIREA ECOSYSTEM                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   IoT Layer      │──────▢│   Edge AI Layer  │──────▢│   Cloud Layer    β”‚
β”‚                  β”‚      β”‚                  β”‚      β”‚                  β”‚
β”‚ β€’ ESP32-S3       β”‚      β”‚ β€’ TFLite Cough   β”‚      β”‚ β€’ Spring Boot    β”‚
β”‚ β€’ INMP441 Mic    β”‚      β”‚ β€’ TFLite Fall    β”‚      β”‚ β€’ PostgreSQL     β”‚
β”‚ β€’ AD8232 ECG     β”‚      β”‚ β€’ DSP Processing β”‚      β”‚ β€’ REST API       β”‚
β”‚ β€’ MAX30205 Temp  β”‚      β”‚ β€’ G-Force Calc   β”‚      β”‚ β€’ WebSocket      β”‚
β”‚ β€’ MPU6050 IMU    β”‚      β”‚ β€’ FreeRTOS Tasks β”‚      β”‚ β€’ SMS Alerts     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                               β”‚
                                                               β”‚
                          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
                          β”‚                                    β”‚
                          β–Ό                                    β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚  Mobile Layer    β”‚              β”‚   Data Layer     β”‚
              β”‚                  β”‚              β”‚                  β”‚
              β”‚ β€’ Flutter App    β”‚              β”‚ β€’ Supabase DB    β”‚
              β”‚ β€’ iOS/Android    β”‚              β”‚ β€’ Time-series    β”‚
              β”‚ β€’ Web Dashboard  β”‚              β”‚ β€’ Health Reports β”‚
              β”‚ β€’ Push Alerts    β”‚              β”‚ β€’ Analytics      β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow

ESP32 Sensors β†’ Edge AI Processing β†’ Cloud Backend β†’ Mobile App β†’ Emergency Contact
     ↓               ↓                      ↓             ↓              ↓
  Raw Data    TFLite Inference        PostgreSQL    Real-time UI    SMS Alert
  Capture     + DSP Analysis           Storage       Dashboard     (if critical)

API Data Flow (every 5 seconds)

Endpoint Data Sent Purpose
POST /api/vitals/event temp, bpm, respiratory rate, leadsOff Continuous vitals monitoring
POST /api/cough/event confidence, audio volume Cough event logging
POST /api/fall/event g-force, GPS, vitals snapshot Fall detection + emergency trigger

πŸ› οΈ Tech Stack

Backend

Java Spring Boot PostgreSQL Maven

Frontend

Flutter Dart

Firmware

ESP32 Arduino TensorFlow Lite

Machine Learning

Python TensorFlow Keras


πŸš€ Installation

Prerequisites

βœ… Java 17+
βœ… Maven 3.6+
βœ… Flutter 3.x
βœ… PlatformIO
βœ… PostgreSQL 15+ (or Supabase account)
βœ… ESP32 hardware + sensors

1️⃣ Backend Setup

# Clone repository
git clone https://github.com/yourusername/airea.git
cd airea/backend

# Create .env file
cat > .env << EOF
SUPABASE_URL=jdbc:postgresql://db.your-project.supabase.co:5432/postgres
SUPABASE_USERNAME=postgres
SUPABASE_PASSWORD=your_password
EOF

# Run backend
mvn clean install
mvn spring-boot:run

Backend runs at: http://localhost:8080

Test it:

curl http://localhost:8080/api/cough/health

2️⃣ Frontend Setup

cd frontend

# Install dependencies
flutter pub get

# Configure API (edit lib/config/api_config.dart)
# Set backendHost = 'localhost' for local testing
# Set backendHost = '192.168.x.x' for mobile device testing

# Run app
flutter run -d chrome     # Web
flutter run -d android    # Mobile

3️⃣ ESP32 Firmware Setup

Hardware Connections (ESP32-S3)

INMP441 Microphone (I2S Audio):
  SCK  β†’ GPIO 41
  WS   β†’ GPIO 42
  SD   β†’ GPIO 2
  VDD  β†’ 3.3V
  GND  β†’ GND

AD8232 ECG Module:
  OUTPUT β†’ GPIO 1 (ADC)
  LO+    β†’ GPIO 6
  LO-    β†’ GPIO 7
  VCC    β†’ 3.3V
  GND    β†’ GND

MAX30205 Temperature (I2C Bus 1):
  SDA  β†’ GPIO 17
  SCL  β†’ GPIO 18
  VIN  β†’ 3.3V
  GND  β†’ GND

MPU6050 IMU (I2C Bus 2):
  SDA  β†’ GPIO 15
  SCL  β†’ GPIO 16
  VCC  β†’ 3.3V
  GND  β†’ GND

Status LED:
  LED  β†’ GPIO 4

Upload Firmware

cd esp32_firmware

# Install PlatformIO CLI
pip install platformio

# The firmware uses WiFiManager for easy WiFi setup
# On first boot, connect to "AIREA-Setup" WiFi network
# Configure your WiFi credentials via the captive portal

# Upload to ESP32-S3
pio run -t upload

# Monitor serial output
pio device monitor -b 115200

Firmware Features

  • FreeRTOS Tasks: Audio inference and network sender run on Core 0
  • WiFiManager: Easy WiFi configuration via captive portal
  • Background HTTP Queue: Non-blocking data transmission
  • ECG DSP: 250Hz sampling with peak detection for BPM
  • Respiratory Rate: EDR (ECG-derived respiration) extraction

πŸ“– Usage

Quick Start

  1. Power on ESP32 with connected sensors
  2. Open mobile app (or web browser)
  3. Enter device ID: ESP32_HEALTH_01
  4. Click "Connect"
  5. View real-time health data!

Test Manually

# Send test cough event
curl -X POST http://localhost:8080/api/cough/event \
  -H "Content-Type: application/json" \
  -d '{
    "deviceId": "ESP32_HEALTH_01",
    "coughType": "dry",
    "confidence": 0.85,
    "audioVolume": 65.5
  }'

# Get statistics
curl http://localhost:8080/api/cough/stats/ESP32_HEALTH_01/today

πŸ“‘ API Endpoints

Base URL

Production: https://airea-production.up.railway.app/api
Local:      http://localhost:8080/api

Authentication Endpoints

Method Endpoint Description
POST /auth/patient/register Register new patient
POST /auth/patient/login Patient login (returns JWT)
POST /auth/doctor/register Register new doctor
POST /auth/doctor/login Doctor login (returns JWT)
POST /auth/forgot-password Request password reset OTP
POST /auth/reset-password Reset password with OTP

Vitals Endpoints

Method Endpoint Description
POST /vitals/event Submit vitals (temp, bpm, respiratory rate)
GET /vitals/device/{deviceId} Get all vitals for device
GET /vitals/latest/{deviceId} Get latest vitals reading
GET /vitals/range/{deviceId} Get vitals in date range

Cough Detection Endpoints

Method Endpoint Description
POST /cough/event Submit cough event
GET /cough/device/{deviceId} Get all cough events
GET /cough/stats/{deviceId}/hour Hourly cough statistics
GET /cough/stats/{deviceId}/today Today's cough statistics
GET /cough/health Health check endpoint

Fall Detection Endpoints

Method Endpoint Description
POST /fall/event Submit fall event (triggers emergency check)
GET /fall/device/{deviceId} Get all fall events
GET /fall/emergency/{deviceId} Get emergency events only

Health Summary Endpoints

Method Endpoint Description
GET /summary/daily/{patientId} Daily health summary with insights
GET /summary/weekly/{patientId} Weekly health summary with trends
GET /summary/cough-analysis/{patientId} Detailed cough pattern analysis

Device Management Endpoints

Method Endpoint Description
POST /device/register Register new device
GET /device/active Get all active devices
POST /device/link Link device to patient

πŸ”Œ Hardware Requirements

Minimum Setup (Cough Detection)

  • ESP32-S3-WROOM ($8-15)
  • INMP441 Microphone ($2-5)
  • Total: ~$15

Full Setup (All Features)

  • ESP32-S3-WROOM
  • INMP441 Microphone
  • AD8232 ECG Module ($5-10)
  • MAX30205 Temperature Sensor ($3-8)
  • MPU6050 Accelerometer/Gyroscope ($2-5)
  • Total: ~$25-50

πŸ“ Project Structure

airea/
β”œβ”€β”€ backend/                      # Spring Boot REST API
β”‚   β”œβ”€β”€ src/main/java/
β”‚   β”‚   β”œβ”€β”€ config/               # Security, CORS, WebSocket config
β”‚   β”‚   β”œβ”€β”€ controller/           # REST endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ AuthController    # Patient/Doctor authentication
β”‚   β”‚   β”‚   β”œβ”€β”€ VitalsController  # Vitals data endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ CoughController   # Cough event endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ FallController    # Fall detection endpoints
β”‚   β”‚   β”‚   └── SummaryController # Health summaries
β”‚   β”‚   β”œβ”€β”€ model/                # JPA entities
β”‚   β”‚   β”‚   β”œβ”€β”€ Patient, Doctor   # User models
β”‚   β”‚   β”‚   β”œβ”€β”€ VitalsEvent       # Temperature, BPM, respiratory rate
β”‚   β”‚   β”‚   β”œβ”€β”€ CoughEvent        # Cough detection events
β”‚   β”‚   β”‚   └── FallEvent         # Fall events with emergency status
β”‚   β”‚   β”œβ”€β”€ repository/           # JPA repositories
β”‚   β”‚   β”œβ”€β”€ service/              # Business logic
β”‚   β”‚   β”‚   β”œβ”€β”€ FallDetectionService   # Emergency detection logic
β”‚   β”‚   β”‚   β”œβ”€β”€ SmsAlertService        # Notify.lk SMS integration
β”‚   β”‚   β”‚   └── SummaryService         # Health insights generation
β”‚   β”‚   └── dto/                  # Data transfer objects
β”‚   └── pom.xml
β”‚
β”œβ”€β”€ frontend/                     # Flutter Cross-Platform App
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ config/               # API configuration, themes
β”‚   β”‚   β”œβ”€β”€ models/               # Data models (Patient, Vitals, etc.)
β”‚   β”‚   β”œβ”€β”€ screens/              # UI screens
β”‚   β”‚   β”‚   β”œβ”€β”€ patient/          # Patient dashboard, summaries
β”‚   β”‚   β”‚   └── doctor/           # Doctor patient management
β”‚   β”‚   β”œβ”€β”€ services/             # API, Auth, Summary services
β”‚   β”‚   β”œβ”€β”€ widgets/              # Reusable UI components
β”‚   β”‚   └── utils/                # Helpers, formatters
β”‚   └── pubspec.yaml
β”‚
β”œβ”€β”€ esp32_firmware/               # ESP32-S3 PlatformIO Project
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   └── main.cpp              # FreeRTOS tasks, sensor reading, ML inference
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ cough_model.h         # TFLite cough detection model
β”‚   β”‚   └── fall_model.h          # TFLite fall detection model
β”‚   └── platformio.ini
β”‚
└── ml-training/                  # Machine Learning Training
    β”œβ”€β”€ cough-training/
    β”‚   β”œβ”€β”€ train_final.py        # Cough CNN model training
    β”‚   β”œβ”€β”€ dataset/              # Audio samples (cough/noise)
    β”‚   └── model.h               # Exported TFLite model
    └── fall-training/
        β”œβ”€β”€ train_fall.py         # Fall detection model training
        β”œβ”€β”€ process_dataset.py    # IMU data preprocessing
        └── IMU-Dataset/          # Accelerometer/gyroscope data

🧠 ML Model Training

Cough Detection Model

cd ml-training/cough-training

# Install dependencies
pip install -r requirements.txt

# Train model (uses dataset/ folder)
python train_final.py

# Output: model.h (TFLite INT8 quantized for ESP32)
  • Architecture: Conv1D β†’ MaxPooling β†’ GlobalAveragePooling β†’ Dense
  • Input: 2-second audio (16000 samples at 16kHz)
  • Output: Binary (cough vs. noise)

Fall Detection Model

cd ml-training/fall-training

# Process IMU dataset
python process_dataset.py

# Train model
python train_fall.py

# Output: fall_model.h (TFLite Float32)
  • Architecture: Conv1D β†’ MaxPooling β†’ Dropout β†’ Dense
  • Input: 200 timesteps Γ— 6 features (3-axis accel + 3-axis gyro)
  • Output: Binary (fall vs. ADL activities)

🚨 Emergency Detection Thresholds

Metric Normal Range Warning Critical (Emergency)
Heart Rate 60-100 BPM <50 or >120 <40 or >150
Temperature 36.1-37.5Β°C >38Β°C <35Β°C or >39.5Β°C
Respiratory Rate 12-20 /min <10 or >25 <8 or >30
Fall G-Force <1.5G >2.0G >2.5G (>3.0G severe)

πŸ—ΊοΈ Roadmap

  • Cough detection with TFLite CNN
  • Real-time Flutter mobile app
  • Cloud database integration (Supabase PostgreSQL)
  • Heart rate monitoring via AD8232 ECG
  • Respiratory rate via ECG-derived respiration
  • Body temperature tracking via MAX30205
  • Fall detection with MPU6050 + G-force analysis
  • Emergency SMS alerts via Notify.lk
  • Daily/Weekly health summaries with AI insights
  • Patient & Doctor authentication with JWT
  • WebSocket real-time vitals streaming
  • Push notifications for mobile
  • Offline data caching
  • Apple Watch / WearOS integration

πŸš€ Deployment

Backend (Railway)

# The backend is configured for Railway deployment
# See railway.toml for configuration

# Database configuration (choose ONE approach)

# Option A (recommended)
SPRING_DATASOURCE_URL=jdbc:postgresql://db.xxx.supabase.co:5432/postgres?sslmode=require
SPRING_DATASOURCE_USERNAME=postgres
SPRING_DATASOURCE_PASSWORD=your_password

# Option B
DATABASE_URL=postgresql://postgres:your_password@db.xxx.supabase.co:5432/postgres

# Required app variables
JWT_SECRET=your_long_secure_secret_key
CORS_ALLOWED_ORIGINS=https://your-frontend-domain.com

# Optional mail (password reset)
MAIL_USERNAME=your_gmail@gmail.com
MAIL_PASSWORD=your_gmail_app_password

# Optional SMS (alerts)
TWILIO_ACCOUNT_SID=your_twilio_account_sid
TWILIO_AUTH_TOKEN=your_twilio_auth_token
TWILIO_PHONE_NUMBER=+1234567890
SMS_ALERTS_ENABLED=true

Production URL: https://airea-production.up.railway.app

Database (Supabase)

  • PostgreSQL 15 hosted on Supabase
  • Automatic backups enabled
  • Connection pooling via PgBouncer

Frontend (Multi-platform)

# Build for different platforms
flutter build apk          # Android
flutter build ios          # iOS
flutter build web          # Web
flutter build macos        # macOS
flutter build windows      # Windows

🀝 Contributing

Contributions are welcome!

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add feature')
  4. Push to branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

MIT License - see LICENSE file


πŸ“§ Contact

Project Link: https://github.com/yourusername/airea


⭐ Star this repository if you found it helpful!

Made with ❀️ by the Airea Team