Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌩️ Decentralized IoT & ML Framework for Hyperlocal Cloudburst Prediction

A low-cost, decentralized early-warning system that combines edge sensing (ESP32 + LoRa), machine learning (Random Forest), and real-time visualization (Flask + MySQL) to predict hyperlocal cloudburst / landslide risk and alert affected areas before disaster strikes.

πŸŽ“ Final Year Major Project


πŸ“– Overview

Traditional weather forecasting operates at a regional scale and often misses hyperlocal triggers for sudden cloudbursts and landslides β€” rapid spikes in soil moisture, rainfall intensity, and humidity in a specific micro-zone (a hillside, a single village, a slope).

This project deploys low-power ESP32 sensor nodes in the field to continuously monitor environmental conditions. Sensor readings are transmitted through two independent, decentralized channels:

  1. LoRa (long-range radio) β†’ to a local receiver node for on-site alerting (LCD display, buzzer, Blynk cloud dashboard, GSM SMS alerts) β€” works even without WiFi/internet at the sensor site.
  2. WiFi (UDP) β†’ directly to a central Flask server, which runs the trained ML model, stores results in MySQL, and serves a live web dashboard.

This dual-path design means the system keeps working locally (buzzer/SMS/LCD) even if the network/internet connection to the central server is down β€” a key requirement for disaster-prone, connectivity-poor regions.


πŸ—οΈ System Architecture

                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                        β”‚     TX Node (ESP32 #1)      β”‚
                        β”‚                             β”‚
                        β”‚ -Soil Moisture + Rain        β”‚
                        β”‚ -DHT11 (Temp + Humidity)     β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                       β”‚
               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
               β”‚                                   β”‚
          LoRa 433MHz                       WiFi (UDP:4210)
               β”‚                                   β”‚
               β–Ό                                   β–Ό

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     RX Node (ESP32 #2)      β”‚     β”‚       Flask ML Server       β”‚
β”‚                             β”‚     β”‚                             β”‚
β”‚ - 16x2 LCD Display          β”‚     β”‚ - RandomForest model        β”‚
β”‚ - Buzzer alarm              β”‚     β”‚   predicts Safe/Danger      β”‚
β”‚ - Blynk cloud dashboard     β”‚     β”‚ - Logs readings to MySQL    β”‚
β”‚ - GSM SMS alert on          β”‚     β”‚ - Sends result back to      β”‚
β”‚   danger detection          β”‚     β”‚   ESP32 over UDP            β”‚
β”‚                             β”‚     β”‚ - Live web dashboard        β”‚
β”‚                             β”‚     β”‚   (auto-refresh, 3s)        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Why decentralized? Each node can independently trigger a local physical alarm (buzzer/LCD/SMS) via LoRa, without depending on internet connectivity β€” while the WiFi/UDP path simultaneously feeds the centralized ML pipeline for logging, prediction, and remote dashboard monitoring.


✨ Features

  • πŸ›°οΈ Dual-channel transmission β€” LoRa for resilient local alerting, WiFi/UDP for cloud-side ML inference
  • πŸ€– ML-based risk classification β€” RandomForestClassifier trained on soil/rain/temperature/humidity features
  • πŸ—„οΈ Persistent logging β€” every reading + prediction stored in MySQL (esp32_logs)
  • πŸ“Ί Live dashboard β€” auto-refreshing web UI showing the latest sensor reading and risk status
  • πŸ”” Multi-modal field alerts β€” LCD display, buzzer, Blynk IoT app notification, and GSM SMS to registered numbers when danger is detected
  • πŸ§ͺ Manual prediction tester (check.py) β€” a standalone form-based UI to test the model with custom sensor values
  • πŸ“Š Synthetic dataset generator (data.py) β€” for bootstrapping/training the model without needing months of real field data

πŸ› οΈ Tech Stack

Layer Technology
Microcontroller ESP32 (x2 β€” TX & RX nodes)
Sensors Soil moisture sensor, Rain sensor, DHT11 (Temp/Humidity)
Long-range comms LoRa SX1278 (433 MHz)
Local alerting 16x2 LCD, Buzzer, GSM module (SIM800L-class, via AT commands)
Cloud IoT dashboard Blynk
Backend server Python, Flask
Machine Learning scikit-learn (RandomForestClassifier), joblib, NumPy, pandas
Database MySQL
Networking UDP sockets (ESP32 ↔ Flask server)
Frontend HTML/CSS (Jinja2 templates)

πŸ“ Repository Structure

.
β”œβ”€β”€ Arduino/
β”‚   β”œβ”€β”€ tx_code/
β”‚   β”‚   └── tx_code.ino        # ESP32 sensor node: reads sensors, sends via LoRa + UDP
β”‚   └── rx_code/
β”‚       └── rx_code.ino        # ESP32 alert node: LoRa receiver, LCD/buzzer/Blynk/GSM alerts
β”œβ”€β”€ templates/
β”‚   └── index.html             # Live web dashboard (auto-refresh every 3s)
β”œβ”€β”€ data.py                    # Generates synthetic training dataset (landslide_data.csv)
β”œβ”€β”€ train.py                   # Trains RandomForestClassifier, saves landslide_model.pkl
β”œβ”€β”€ app.py                     # Flask server + UDP listener + ML inference + MySQL logging
β”œβ”€β”€ check.py                   # Standalone manual prediction tester (web form)
└── README.md

πŸ“Έ Output Screenshots

Live Web Dashboard

Flask live dashboard showing sensor readings and risk status

Server Console (UDP Listener + ML Prediction Log)

Terminal output showing received sensor packets and predictions

Hardware Setup

TX Node (Sensor Node) RX Node (Alert Node)
TX ESP32 node with soil moisture, rain sensor, and DHT11 wiring RX ESP32 node with LoRa, LCD, buzzer wiring

Blynk App Dashboard & WiFi Hotspot Connection

Blynk App ESP32 Hotspot Connection
Blynk mobile app showing live sensor values ESP32 connected via WiFi hotspot

LCD Display Output

16x2 LCD showing soil, rain, temperature and humidity readings

βš™οΈ Setup & Installation

1. Hardware Requirements

  • 2x ESP32 dev boards
  • 2x LoRa SX1278 modules (433 MHz)
  • Soil moisture sensor + Rain sensor (analog)
  • DHT11 temperature/humidity sensor
  • 16x2 LCD (parallel interface)
  • Buzzer
  • GSM module (SIM800L or similar, AT-command based)
  • Jumper wires, breadboard/PCB, power supply

2. Arduino Firmware

Install the following libraries via Arduino IDE Library Manager:

  • WiFi, WiFiUdp (bundled with ESP32 board package)
  • LoRa (by Sandeep Mistry)
  • DHT sensor library (Adafruit)
  • LiquidCrystal
  • BlynkSimpleEsp32

Before flashing, update the following in each .ino file with your own credentials (do not commit real values to GitHub):

  • ssid / password β€” your WiFi network
  • targetIP in tx_code.ino β€” the local IP address of the machine running app.py
  • BLYNK_TEMPLATE_ID / BLYNK_TEMPLATE_NAME / BLYNK_AUTH_TOKEN β€” from your own Blynk console
  • GSM destination phone numbers in rx_code.ino

Flash tx_code.ino to the sensor (TX) ESP32 and rx_code.ino to the alert (RX) ESP32.

3. Python / Server Setup

# Clone the repo
git clone https://github.com/mageshit24/A-Decentralized-IoT-and-Machine-Learning-Framework-for-Hyperlocal-Cloudburst-Prediction.git
cd A-Decentralized-IoT-and-Machine-Learning-Framework-for-Hyperlocal-Cloudburst-Prediction

# Install dependencies
pip install flask mysql-connector-python joblib numpy pandas scikit-learn

4. Database Setup

Create the MySQL database and table used by app.py:

CREATE DATABASE newschema;
USE newschema;

CREATE TABLE esp32_logs (
    id INT AUTO_INCREMENT PRIMARY KEY,
    v1 INT,
    v2 INT,
    v3 INT,
    v4 INT,
    prediction INT,
    timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Update the db_config dictionary in app.py with your own MySQL credentials β€” ideally loaded from environment variables rather than hardcoded.

5. Train the Model

python data.py     # generates landslide_data.csv (synthetic data)
python train.py    # trains RandomForestClassifier, saves landslide_model.pkl

6. Run the Server

python app.py

This starts:

  • A UDP listener on port 4210 (receives sensor packets from the ESP32 TX node)
  • A Flask web server on http://0.0.0.0:5000 (live dashboard)

7. (Optional) Manual Prediction Tester

python check.py

Opens a simple web form at http://localhost:5000 to manually enter sensor values and test the model's prediction without hardware.


🧠 Machine Learning Model

  • Algorithm: Random Forest Classifier (100 estimators)
  • Features: v1 (soil), v2 (rainfall), v3 (temperature), v4 (humidity)
  • Target: Binary risk label β€” 0 = Safe, 1 = Danger
  • Training/test split: 80/20
  • The current dataset (data.py) is synthetically generated using threshold-based rules, intended as a placeholder/bootstrap dataset. For production-grade accuracy, retrain on real historical rainfall/landslide data for your target region.

πŸ“‘ Data Flow Summary

  1. TX ESP32 reads soil, rain, temperature, and humidity sensors.
  2. Values are sent via LoRa to the RX ESP32 and via WiFi/UDP to the Flask server.
  3. Flask server runs the ML model on the incoming reading and classifies it as Safe (S) or Danger (D).
  4. The result is logged to MySQL and sent back to the TX node over UDP.
  5. RX ESP32 (which received the same data via LoRa) displays the reading on its LCD, and if a Danger signal (D) was relayed/detected, triggers the buzzer, updates the Blynk dashboard, and sends an SMS alert via the GSM module.
  6. The Flask dashboard (templates/index.html) auto-refreshes every 3 seconds to show the latest reading and risk status.

πŸ”’ Security Notes

This is an academic prototype. Before deploying or sharing further, replace all hardcoded credentials (WiFi password, MySQL password, Blynk auth token, GSM phone numbers) with environment variables / a .gitignore-excluded config file, and avoid committing secrets to version control.


πŸš€ Future Improvements

  • Replace synthetic training data with real historical meteorological/landslide datasets
  • Add HTTPS and authentication to the Flask dashboard
  • Move from polling/UDP to MQTT for more robust IoT messaging
  • Add a historical trends chart (not just the latest reading) to the dashboard
  • Support multiple sensor nodes per region for true hyperlocal coverage
  • Containerize the backend (Docker) for easier deployment

πŸ‘€ Author

Magesh Final Year Major Project β€” IoT & Machine Learning for Disaster Risk Prediction

πŸ“‡ LinkedIn


πŸ“„ License

This project is currently unlicensed. Consider adding an open-source license (e.g., MIT) if you'd like others to reuse or contribute to it.

About

A decentralized IoT + Machine Learning system for hyperlocal cloudburst/landslide risk prediction. ESP32 sensor nodes (soil moisture, rainfall, DHT11) transmit over LoRa and WiFi-UDP to a Flask server running a RandomForest classifier, with real-time MySQL logging, a live web dashboard, and Blynk/GSM/buzzer field alerts.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages