A Hybrid Deep Learning Ecosystem for Proactive Air Quality Forecasting & Anomaly Detection
EnviroSense AI is an end-to-end environmental intelligence platform. By bridging the gap between raw IoT sensor data and advanced Deep Learning, the system transforms air quality monitoring from a reactive "status check" into a proactive "early warning system."
The platform follows a modular 4-layer architecture designed for high availability and analytical depth:
- Edge Layer: ESP32 nodes capturing high-fidelity particulate matter (PM1.0, PM2.5, PM10) and particle bin counts (0.3μm–10μm) via UART/Modbus protocols.
- Persistence Layer: TimescaleDB (PostgreSQL) optimized for high-velocity time-series storage and hypertable partitioning.
- Inference Layer: FastAPI serving pre-trained Deep Learning models (LSTM/Autoencoders) for real-time forecasting and anomaly detection.
- Presentation Layer: React PWA utilizing WebSockets for instant data updates and cross-platform accessibility.
This project implements rigorous data science workflows to ensure accuracy and reliability:
- Time-Series Decomposition: Statistical separation of raw data into Trend, Seasonality, and Residuals to validate environmental cycles.
- Size-Distribution Profiling: Analyzing shifts in particle bin counts (0.3μm to 10μm) to identify pollutant sources (e.g., smoke vs. dust).
- Environmental Correlation: Quantifying the impact of Temperature and Humidity on Particulate Matter concentrations through multivariate regression.
- Sequence Modeling (LSTM): Implementing Long Short-Term Memory neural networks to capture temporal dependencies and predict PM levels for a 6-hour horizon.
- Unsupervised Anomaly Detection: Using Reconstruction Error thresholds from trained Autoencoders to flag sensor hardware failures or localized extreme events.
- Hardware: ESP32, Next-PM Optical Sensor, DHT22.
- Backend: Python 3.10+, FastAPI, SQLAlchemy, Paho-MQTT.
- Frontend: React.js, Vite, Tailwind CSS, Recharts.
- Database: PostgreSQL with TimescaleDB extension.
- ML/DS Libraries: TensorFlow/Keras, Scikit-learn, Pandas, NumPy, Plotly.
To maintain a production-ready environment, development is conducted via Remote-SSH, ensuring that high-compute tasks remain on the server while code is authored in a local IDE.
Standardize connections via a non-root user to maintain security and system integrity.
SSH Configuration (~/.ssh/config):
Host envirosense-vps
HostName <YOUR_VPS_IP>
User <YOUR_USERNAME>
IdentityFile ~/.ssh/id_ed25519
All analytics and subscriber logic should run within a dedicated Python Virtual Environment to prevent dependency drift.
# Activation and Verification
source .venv/bin/activate
python -c "import sys; print(sys.prefix)" # Confirms isolated environment
When running analytical dashboards (e.g., Plotly Dash or Streamlit) on the VPS, use VS Code Port Forwarding to tunnel the web interface to your local browser:
- Remote Port:
8050(or your app's port) - Local Address:
localhost:8050
- Clone the Repository:
git clone https://github.com/YourUsername/EnviroSense-AI.git
cd EnviroSense-AI
- Environment Setup:
Install dependencies from
requirements.txtinto your virtual environment. - Database Configuration:
Ensure the PostgreSQL
pg_hba.confallows connections for your specific database user. - Service Deployment:
Configure the
subscriber.pyas asystemdservice for 24/7 data persistence.