Project X-RayIn Progress

AI-Augmented Edge Health Monitoring System

AI-Augmented Edge Health Monitoring System

My final year project. I built an edge computing system that reads patient vitals (heart rate, SpO2, body temperature, respiratory rate) off an ESP32 and runs ML models locally to flag cardiovascular and respiratory risks early. The whole point was to cut cloud dependency so it works even with patchy connectivity.

PythonFlaskTensorFlowESP32IoTEdge AIFirebaseMachine Learning

The Problem

Context & Problem

Traditional remote health monitoring systems stream raw sensor data to the cloud for processing. This creates a single point of failure: if the network drops, the monitoring stops. For patients with cardiovascular or respiratory conditions, even brief gaps in monitoring can delay critical alerts.

Existing Solutions

Existing wearables (Fitbit, Apple Watch) provide basic vitals but lack clinical-grade analysis. Hospital-grade monitors are expensive and require constant network connectivity to a central server.

The Goal

Build an edge-computing system that reads patient vitals locally, runs ML inference on-device, and only syncs summarized results to the cloud — ensuring continuous monitoring even with patchy connectivity.

Target Users

Patients with chronic conditions, rural clinic staff, and home-care providers who need reliable health monitoring without enterprise-grade network infrastructure.

Requirements

  • Real-time heart rate monitoring via PPG sensor
  • SpO2 (blood oxygen saturation) measurement
  • Body temperature tracking
  • Respiratory rate extraction using RIIV algorithm
  • On-device ML risk prediction (cardiovascular & respiratory)
  • Gemini AI-powered explainable health insights
  • Live dashboard with historical trend visualization
  • Alert system for abnormal vital readings
  • Cloud sync when connectivity is available
  • Sub-50ms edge inference latency
  • Operation during network outages (offline-first)
  • Battery-efficient sensor polling on ESP32
  • Data accuracy validated against clinical datasets
  • Secure data transmission (TLS encryption)
  • Responsive dashboard across devices

UI / UX Design

Design Process
Research & Dataset Analysis→
Sensor Integration Prototyping→
Algorithm Development→
Dashboard Wireframes→
High-Fidelity Dashboard UI→
Implementation & Iteration
Wireframe/Screen

Patient Dashboard

Real-time vitals display with trend graphs and AI risk assessment panel.

Wireframe/Screen

Alert Management

Notification center for threshold breaches and anomaly detections.

Wireframe/Screen

Historical Analytics

Time-series charts showing vital trends over days and weeks.

Wireframe/Screen

Sensor Status

Live sensor connection status, battery level, and data quality indicators.

System Architecture

Interactive

A three-tier edge computing architecture: hardware sensors feed an ESP32 microcontroller for local ML inference, which syncs processed results to Firebase for dashboard consumption.

Analog/I2C signalsProcessed vitalsValidated dataReal-time syncHealth contextXAI insightsPPG / Temp SensorsMAX30102 + DS18B20ESP32 Edge DeviceESP32 + MicroPytho…Flask API ServerPython + FlaskFirebaseFirestore + AuthWeb DashboardReact + Chart.jsGemini AIGoogle Gemini API

Frontend Implementation

A responsive React dashboard that subscribes to Firebase real-time updates, rendering live vitals with Chart.js and displaying Gemini AI-generated health insights.

Component Architecture
App
├─AuthProvider
├─Dashboard
├─VitalsGrid
├─HeartRateCard
├─SpO2Card
├─TempCard
└─RespRateCard
├─TrendChart
├─AIInsightPanel
└─AlertNotifications
├─HistoryView
├─TimeSeriesChart
└─DataExport
└─SensorStatus
State Management

React state with Firebase real-time listeners (onSnapshot) for live data streaming. No external state library needed — Firebase handles the real-time sync layer.

Routing

React Router with protected routes for authenticated dashboard views.

API Integration

Firebase SDK for real-time data subscription. Direct Flask API calls for on-demand ML predictions and Gemini AI insights.

Backend Architecture

A Flask API server handles advanced ML model serving, data validation, and Gemini AI integration. The ESP32 communicates directly with this server for real-time predictions.

API Endpoints
POST/api/vitals
GET/api/vitals/latest
POST/api/predict/risk
GET/api/insights/:patientId
GET/api/history/:patientId
POST/api/alerts
Backend Layers
  • 01Route Layer
  • 02Controller Layer
  • 03ML Service Layer
  • 04Data Validation Layer
  • 05External API Layer (Gemini)
Implementation Example
RIIV Respiratory Rate Extraction
python
def extract_respiratory_rate(ppg_signal, fs=125):
    """Extract respiratory rate from PPG using RIIV method.
    Validated on PhysioNet BIDMC dataset (53 patients).
    Achieved MAE of 3.03 breaths/min.
    """
    # Band-pass filter for respiratory frequencies
    b, a = butter(4, [0.1, 0.5], btype='band', fs=fs)
    respiratory_signal = filtfilt(b, a, ppg_signal)
    
    # Peak detection for breath counting
    peaks, _ = find_peaks(respiratory_signal,
                          distance=fs * 1.5)
    
    # Calculate rate from inter-breath intervals
    intervals = np.diff(peaks) / fs
    resp_rate = 60.0 / np.mean(intervals)
    
    return resp_rate

Database & Storage

Firebase Firestore

Firebase Firestore provides real-time NoSQL storage for vital readings, patient profiles, and alert history. Chosen for its real-time sync capabilities and seamless integration with the web dashboard.

patients

Patient profile and metadata

Fields
patientIdnameageconditionsassignedDevicescreatedAt
Relations
  • ↳Has many vitals
  • ↳Has many alerts
vitals

Time-series vital readings from edge device

Fields
vitalIdpatientIdheartRatespo2temperaturerespRateriskScoretimestamp
Relations
  • ↳Belongs to patient
alerts

Threshold breach and anomaly alerts

Fields
alertIdpatientIdtypeseveritymessageacknowledgedtimestamp
Relations
  • ↳Belongs to patient
insights

AI-generated health insights from Gemini

Fields
insightIdpatientIdgeminiResponsecontexttimestamp
Relations
  • ↳Belongs to patient

Information Architecture

Sensor → Edge AI → Cloud → Dashboard

Sensor ReadingMAX30102

PPG sensor captures photoplethysmography waveform at 125 Hz

Signal ProcessingESP32

ESP32 filters noise and extracts features from raw signal

RIIV ExtractionMicroPython

Respiratory rate extracted using Respiration-Induced Intensity Variation

Edge ML InferenceTensorFlow Lite

TinyML model predicts cardiovascular and respiratory risk scores

API TransmissionREST API

Processed vitals sent to Flask server over HTTPS

Validation & StorageFlask + Firebase

Server validates data and writes to Firestore

AI AnalysisGemini API

Gemini AI generates explainable health insights

Real-time SyncFirebase SDK

Dashboard receives live updates via Firestore listeners

UI UpdateReact

Charts and vital cards re-render with latest data

Security & Auth

Firebase Authentication handles user identity. Patients and healthcare providers authenticate via email/password. Role-based access ensures patients only see their own data.

Authentication Flow
User enters credentials→
Firebase Auth validates identity→
JWT token issued→
Token attached to Firestore queries→
Security rules enforce data access→
Session persisted locally
Role-Based Access
PatientView own vitals, alerts, and AI insights
Healthcare ProviderView assigned patients, manage alerts, configure thresholds
AdminSystem configuration, user management, device registration

Development Timeline

Technical Decisions

ESP32 for edge processing instead of Raspberry Pi

Reason

Lower power consumption, smaller form factor, built-in WiFi/BLE, and sufficient compute for TinyML inference.

Tradeoff

Limited memory and processing power compared to Raspberry Pi.

Alternative Considered

Raspberry Pi 4

Why Rejected

Overkill for sensor reading and simple ML inference. Higher power draw makes it impractical for battery-powered wearable use.

Firebase Firestore over PostgreSQL

Reason

Real-time sync capabilities are essential for live dashboard updates. Firestore provides this out of the box with minimal backend code.

Tradeoff

Less flexible querying compared to SQL. Higher cost at scale.

Alternative Considered

PostgreSQL with WebSocket server

Why Rejected

Would require building and maintaining a WebSocket server for real-time updates. Firebase provides this for free at the project's scale.

RIIV method for respiratory rate over frequency-domain methods

Reason

RIIV works well with noisy PPG signals from low-cost sensors. Validated on real clinical data (PhysioNet BIDMC).

Tradeoff

Less accurate than hospital-grade capnography but appropriate for continuous home monitoring.

Alternative Considered

FFT-based spectral analysis

Why Rejected

More susceptible to motion artifacts in non-clinical settings. RIIV showed better robustness in our validation.

Challenges & Solutions

#01

Noisy PPG signals from low-cost MAX30102 sensor

Solution

Implemented multi-stage signal processing: band-pass filter → moving average → peak detection with adaptive thresholds. Validated against clinical-grade sensors.

Impact

Achieved clinically acceptable accuracy despite using a $3 sensor module.

#02

Running ML models on ESP32's limited memory (520KB SRAM)

Solution

Used TensorFlow Lite model quantization (float32 → int8) to reduce model size by 75%. Optimized feature extraction to minimize memory allocation.

Impact

Successfully deployed inference on microcontroller with <50ms latency.

#03

Maintaining monitoring during network outages

Solution

Implemented local circular buffer on ESP32 that stores up to 24 hours of readings. Automatic batch sync when connectivity is restored.

Impact

Zero data loss during network interruptions in testing.

Testing & Validation

Testing focused on ML model validation against clinical datasets and end-to-end hardware-software integration testing.

Testing Types
ML Model ValidationSignal Processing Unit TestsAPI Integration TestsHardware Integration TestsEnd-to-End System Tests
CI/CD Pipeline
Unit Tests (PyTest)→
Model Validation (BIDMC Dataset)→
API Tests (Postman)→
Hardware Loop Tests→
Dashboard Manual Testing

Deployment Architecture

PlatformFirebase Hosting + Local Flask Server

Flask server deployed for development. Firebase handles production data layer. ESP32 firmware flashed via USB.

Pipeline
Code committed to GitHub→
Flask server deployed locally / on VM→
Firebase Firestore rules deployed via CLI→
ESP32 firmware compiled and flashed→
Dashboard deployed via Firebase Hosting

Results & Metrics

3.03 br/minRespiratory Rate MAEValidated on PhysioNet BIDMC dataset (53 patients)
<50msEdge Inference LatencyOn-device ML prediction time on ESP32
53 patientsDataset SizeReal clinical data from PhysioNet BIDMC
75%Model Size ReductionVia TensorFlow Lite int8 quantization

Key Learnings

Technical
  • Signal processing fundamentals are critical for IoT health applications — no amount of ML can fix garbage input data.
  • TensorFlow Lite quantization is powerful but requires careful validation to ensure accuracy is preserved.
  • ESP32's dual-core architecture allows running sensor polling and ML inference concurrently.
Architecture
  • Edge-first architecture dramatically improves reliability in connectivity-limited environments.
  • Firebase's real-time sync eliminates the need for a custom WebSocket implementation at this scale.
  • Separating edge inference from cloud-based AI analysis provides the best of both worlds.
Product
  • Healthcare applications demand higher accuracy validation standards than typical ML projects.
  • Explainable AI (via Gemini) is essential — healthcare providers need to understand *why* an alert was raised.
  • Battery life is a first-class design constraint for wearable health devices.
What I'd Do Differently
  • ↻Start with a more comprehensive dataset beyond BIDMC for respiratory rate validation.
  • ↻Design the ESP32 firmware in C++ instead of MicroPython for better memory efficiency.
  • ↻Build a mobile app alongside the web dashboard for on-the-go monitoring.