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.
The 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 SolutionsExisting 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.
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 UsersPatients with chronic conditions, rural clinic staff, and home-care providers who need reliable health monitoring without enterprise-grade network infrastructure.
Requirements
UI / UX Design
Patient Dashboard
Real-time vitals display with trend graphs and AI risk assessment panel.
Alert Management
Notification center for threshold breaches and anomaly detections.
Historical Analytics
Time-series charts showing vital trends over days and weeks.
Sensor Status
Live sensor connection status, battery level, and data quality indicators.
System Architecture
InteractiveA three-tier edge computing architecture: hardware sensors feed an ESP32 microcontroller for local ML inference, which syncs processed results to Firebase for dashboard consumption.
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.
React state with Firebase real-time listeners (onSnapshot) for live data streaming. No external state library needed — Firebase handles the real-time sync layer.
React Router with protected routes for authenticated dashboard views.
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.
- 01Route Layer
- 02Controller Layer
- 03ML Service Layer
- 04Data Validation Layer
- 05External API Layer (Gemini)
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_rateDatabase & Storage
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.
Patient profile and metadata
- ↳Has many vitals
- ↳Has many alerts
Time-series vital readings from edge device
- ↳Belongs to patient
Threshold breach and anomaly alerts
- ↳Belongs to patient
AI-generated health insights from Gemini
- ↳Belongs to patient
Information Architecture
Sensor → Edge AI → Cloud → Dashboard
PPG sensor captures photoplethysmography waveform at 125 Hz
ESP32 filters noise and extracts features from raw signal
Respiratory rate extracted using Respiration-Induced Intensity Variation
TinyML model predicts cardiovascular and respiratory risk scores
Processed vitals sent to Flask server over HTTPS
Server validates data and writes to Firestore
Gemini AI generates explainable health insights
Dashboard receives live updates via Firestore listeners
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.
Development Timeline
Technical Decisions
ESP32 for edge processing instead of Raspberry Pi
Lower power consumption, smaller form factor, built-in WiFi/BLE, and sufficient compute for TinyML inference.
Limited memory and processing power compared to Raspberry Pi.
Raspberry Pi 4
Why RejectedOverkill for sensor reading and simple ML inference. Higher power draw makes it impractical for battery-powered wearable use.
Firebase Firestore over PostgreSQL
Real-time sync capabilities are essential for live dashboard updates. Firestore provides this out of the box with minimal backend code.
Less flexible querying compared to SQL. Higher cost at scale.
PostgreSQL with WebSocket server
Why RejectedWould 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
RIIV works well with noisy PPG signals from low-cost sensors. Validated on real clinical data (PhysioNet BIDMC).
Less accurate than hospital-grade capnography but appropriate for continuous home monitoring.
FFT-based spectral analysis
Why RejectedMore susceptible to motion artifacts in non-clinical settings. RIIV showed better robustness in our validation.
Challenges & Solutions
Noisy PPG signals from low-cost MAX30102 sensor
Implemented multi-stage signal processing: band-pass filter → moving average → peak detection with adaptive thresholds. Validated against clinical-grade sensors.
Achieved clinically acceptable accuracy despite using a $3 sensor module.
Running ML models on ESP32's limited memory (520KB SRAM)
Used TensorFlow Lite model quantization (float32 → int8) to reduce model size by 75%. Optimized feature extraction to minimize memory allocation.
Successfully deployed inference on microcontroller with <50ms latency.
Maintaining monitoring during network outages
Implemented local circular buffer on ESP32 that stores up to 24 hours of readings. Automatic batch sync when connectivity is restored.
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.
Deployment Architecture
Flask server deployed for development. Firebase handles production data layer. ESP32 firmware flashed via USB.
Results & Metrics
Key Learnings
- 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.
- 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.
- 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.
- ↻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.