A comprehensive real-time air quality monitoring system built with ESP32, FastAPI, and React. Monitor temperature, humidity, and air quality with beautiful visualizations and historical data analysis.
- Live Sensor Data: Temperature, humidity, and air quality readings every 2 seconds
- Visual Indicators: LED indicators and LCD display on ESP32
- Audio Alerts: Buzzer alerts for poor air quality
- Auto-Refresh Dashboard: Automatic updates every 5 seconds
- Live Charts: Real-time line charts for the last hour
- Historical Trends: Area charts with 24-hour, 7-day, and 14-day views
- Interactive Controls: Toggle between different metrics and time ranges
- Statistics Dashboard: Min/Max/Average calculations
- Automatic Aggregation: Hourly and daily data aggregation
- Smart Retention: 24-hour raw data, 7-day hourly, 14-day daily aggregates
- CSV Export: Download historical data for external analysis
- Database Optimization: Automatic cleanup and indexing
- Air Quality Classification: Good, Moderate, Poor
- Connection Status: Real-time backend connectivity indicator
- Health Checks: System health monitoring endpoint
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ESP32 (Sensor Node) β
β ββ DHT11 (Temperature & Humidity) β
β ββ MQ135 (Air Quality) β
β ββ LCD Display (16x2) β
β ββ LED Indicators β
β ββ WiFi Communication β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ
β HTTP POST (JSON) every 2 seconds
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend (Python 3.10+) β
β ββ RESTful API β
β ββ Async SQLAlchemy ORM β
β ββ Background Tasks (Aggregation/Cleanup) β
β ββ CORS Middleware β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ
β
β SQLite Database
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Database Layer β
β ββ sensor_readings (raw data) β
β ββ hourly_aggregates (7-day retention) β
β ββ daily_aggregates (14-day retention) β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ
β REST API
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β React Frontend (Vite + Recharts) β
β ββ Real-time Dashboard β
β ββ Interactive Charts β
β ββ Statistics Cards β
β ββ Export Functionality β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- ESP32 Development Board (ESP32-WROOM-32 or similar)
- DHT11 Sensor - Temperature & Humidity
- MQ135 Sensor - Air Quality (Gas sensor)
- 16x2 I2C LCD Display
- LEDs - 3x Green, 3x Red
- Buzzer - Active or Passive
- Breadboard & Jumper Wires
- USB Cable - For programming and power
| Component | ESP32 Pin |
|---|---|
| DHT11 Data | GPIO 4 |
| MQ135 Analog | GPIO 34 (ADC1_CH6) |
| Green LED | GPIO 12 |
| Red LED | GPIO 14 |
| Buzzer | GPIO 27 |
| LCD SDA | GPIO 21 (I2C) |
| LCD SCL | GPIO 22 (I2C) |
- Python 3.10 or higher
- uv (Python package installer) or pip
- SQLite 3
- Node.js 18 or higher
- npm or yarn
- Arduino IDE 2.x or PlatformIO
- ESP32 Board Support
git clone https://github.com/nxd010/Vayu.git
cd vayucd backend
# Using uv (recommended)
uv init
uv sync
# Or using pip
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
cd frontend
# Install dependencies
npm install
# Or using yarn
yarn installEdit esp32/node.ino:
// WiFi credentials
const char* ssid = "YOUR_WIFI_SSID";
// Backend server URL (use your laptop's local IP)
const char* serverUrl = "http://XXX.XXX.XXX.XXX:8000/api/sensor-data";Finding your local IP:
- Linux/Mac:
ip addr showorifconfig - Windows:
ipconfig
Edit in esp32/vayu_esp32_client.ino:
const float AQ_GOOD_MAX = 1.0; // Voltage threshold for "Good"
const float AQ_MODERATE_MAX = 2.0; // Voltage threshold for "Moderate"
// Above 2.0V = "Poor"cd backend
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000Backend will be available at: http://localhost:8000
API Documentation: http://localhost:8000/docs
cd frontend
npm run devFrontend will be available at: http://localhost:5173
- Connect ESP32 via USB
- Open Serial Monitor (115200 baud) to see logs
- Upload the sketch
- Monitor the output for connection status
Expected Serial Output:
WiFi Connected!
IP Address: 192.168.1.102
Backend is reachable!
Current Readings:
Temperature: 25.3Β°C
Humidity: 62%
Air Quality: 1.23V (Good)
Data sent successfully!
GET /healthReturns system health status.
Get Latest Reading
GET /api/sensor-data/latestGet Time Range
GET /api/sensor-data/range?hours=1Get Hourly Aggregates
GET /api/sensor-data/hourly?hours=24Get Daily Aggregates
GET /api/sensor-data/daily?days=7Post Sensor Data (ESP32)
POST /api/sensor-data
Content-Type: application/json
{
"temperature": 25.5,
"humidity": 60.0,
"airQualityVoltage": 1.2,
"airQualityLevel": "Good"
}GET /api/statistics?hours=24GET /api/export/csv?hours=168Full API documentation available at: http://localhost:8000/docs (Swagger UI)



