Skip to content
rafiul254Public

About

Edge-Intelligent Load Shedding Prediction and Real-Time Monitoring System for Bangladesh Micro-Level Distribution Grids.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

EdgeVolt — edge-intelligent load-shedding prediction and power-quality monitoring

Concept illustration — the dashboard values shown are mock data. Real hardware photo below.



⚡ EdgeVolt

Edge-intelligent load-shedding prediction and real-time power-quality monitoring
for micro-level distribution grids in Bangladesh

A ≈ BDT 2,000 (~USD 17) ESP32 node that raises alerts offline, on-device,
plus a server-side model that forecasts outages 30 minutes ahead.


License: MIT Status IEEE CS BD

Python ESP32 FastAPI XGBoost Streamlit MQTT InfluxDB Docker


📰 Read the Medium article  ·  🖼️ View the poster  ·  🚀 Quick start  ·  🔌 Hardware  ·  📊 Results

Developed by Md. Rafiul Islam · Dept. of IoT & Robotics Engineering, University of Frontier Technology, Bangladesh (UFTB)


✨ At a glance

💰 Cost ⏱️ Forecast horizon 🧠 Edge alert latency 📈 Benchmark
≈ BDT 2,000
(~USD 17 / node)
30 min ahead
(≈ 13 min lead on gradual events)
< 1 s, works offline 92 events, 60 days
PR-AUC 0.484 (≈ 13× random)

🖼️ Research poster

EdgeVolt research poster — problem, architecture, methodology, prototype, results and next steps

Click the poster for the full-resolution version. All ML figures on it come from the simulated benchmark described below.

📰 Read the article

EdgeVolt, explained. A plain-language walkthrough of why load shedding needs edge intelligence, how the two-model design works, and what building the node taught us.

👉 Read it on Medium  


Project status

Please read. The software pipeline is complete and verified end-to-end. All machine-learning results below come from a 60-day simulated benchmark; they validate the method, not real-grid performance. The hardware node is assembled; calibration and live data collection are in progress.

Area Status
Edge firmware (sampling, RMS, offline alerts, MQTT) ✅ done
Backend, dashboard, replay demo, REST API ✅ done
ML pipeline (leakage-safe, chronological) on simulated data ✅ done
Hardware prototype assembled ✅ done
Calibration & safe mains enclosure ✅ done
~1 month of real labelled data, retraining ⏭️ next (plan)

📚 Table of contents

  1. Why EdgeVolt?
  2. Features
  3. How it works — edge intelligence
  4. Hardware
  5. Results (simulated benchmark)
  6. Quick start
  7. REST API
  8. Repository structure
  9. Roadmap
  10. Limitations
  11. Safety
  12. Authors, citation, license

Why EdgeVolt?

Rolling load shedding interrupts supply for hours at a time, yet consumers at the distribution node get no advance warning, and voltage-quality problems (sags, brownouts) go unrecorded below the substation. Cloud-only IoT monitors fail exactly when they are needed: during load shedding the router is often down too.

EdgeVolt combines two layers:

Layer Where Job
🌲 Edge decision tree On the ESP32 Classifies normal / sag / outage every second and drives LEDs + buzzer — works with no network
🚀 XGBoost forecaster Server Uses ~1 h of history to estimate the probability of an outage in the next 30 min

Features

  • 📟 Measures Vrms, Irms, frequency, temperature, humidity at 1 Hz (200 ms analysis windows)
  • 🧠 Offline alerting (depth-3 tree thresholds in firmware) — survives router / ISP failure
  • 🔋 Powered from a power bank, so the node keeps running and records the collapse during an outage
  • 📡 MQTT telemetry with Last-Will status (a dead node is itself an outage marker)
  • 🗄️ InfluxDB time-series storage, FastAPI backend, 5-tab Streamlit dashboard (Overview · Trends · Anomalies · Cost · Prediction)
  • 💸 BDT cost-of-outage estimate and replay mode to demo any historical timestamp without hardware
  • 🧪 Leakage-safe ML pipeline: chronological split, in-outage rows removed, threshold tuned on validation only
  • 🔁 Data-source agnostic: replace the synthetic CSV with real telemetry and re-run the same scripts

How it works — edge intelligence

Edge intelligence means making the decision where the data is created (on the device) instead of sending everything to a cloud and waiting for an answer. It matters here because of reliability, latency (<1 s alarms), bandwidth (1 Hz summaries instead of kHz waveforms) and privacy (raw waveforms stay local).

flowchart LR
  subgraph EDGE["Tier 1 — Edge node (ESP32)"]
    S1[ZMPT101B<br/>voltage] --> P[200 ms windows<br/>RMS · frequency]
    S2[SCT-013-030<br/>current] --> P
    S3[DHT22<br/>temp · humidity] --> P
    P --> T{{Edge decision tree<br/>V &lt; 170 V outage<br/>V &lt; 198 V or ΔV &lt; −6 V sag}}
    T --> A[LEDs + buzzer<br/>works offline]
  end
  P -- "MQTT 1 Hz" --> M[Mosquitto]
  subgraph SRV["Tier 2/3 — Server"]
    M --> SUB[Subscriber<br/>sanity validation] --> DB[(InfluxDB)]
    DB --> API[FastAPI<br/>+ XGBoost 30-min forecast] --> UI[Streamlit dashboard<br/>+ BDT cost]
  end
Loading

Why two models? The tree only sees the present, so it reacts instantly but cannot forecast. XGBoost needs 54 features built from up to 60 min of history, which is too heavy for an ESP32. Train big in the cloud, run small at the edge.

Hardware

The real prototype

Annotated photo of the real EdgeVolt bench prototype

Bench prototype, work in progress. It is not a certified mains installation — see Safety. Calibration and an enclosed, fused mains-side adapter are still to be completed.

Part Role Notes
ESP32-WROOM-32 DevKit V1 Controller Analog inputs on ADC1 only (ADC2 is unusable with WiFi)
ZMPT101B AC voltage Connected in parallel across live/neutral
SCT-013-030 (30 A : 1 V) AC current Built-in burden → no external burden resistor; clamp one conductor
DHT22 Temp / humidity GPIO 4
Active buzzer + red/green LEDs Local alerts GPIO 25 / 26 / 27 (220 Ω for LEDs)
5 V power bank Supply Survives load shedding

Estimated node cost ≈ BDT 2,000 (ESP32 450, ZMPT101B 450, CT 350, DHT22 250, wiring 500) — a planning estimate, not audited spend.

Pin map: GPIO34 ← ZMPT101B OUT · GPIO35 ← CT bias node J · GPIO4 ← DHT22 · GPIO25 buzzer · GPIO26 red · GPIO27 green.

SCT-013-030 current interface

Full wiring tables, bias network, calibration and bring-up order: docs/HARDWARE.md.

Results (simulated benchmark)

Benchmark: 60 days, 1-min resolution, 92 labelled events (60 gradual with a voltage precursor, 32 sudden). Label = an outage starts within the next 30 min. Strictly chronological 70/15/15 split; 12,148 test rows, 450 positives (3.7 %). Because outages are rare, raw accuracy is misleading (always predicting "no outage" already scores 96.3 %), so precision / recall / PR-AUC are reported.

Operating point Accuracy Precision Recall PR-AUC
Tuned threshold τ = 0.67 97.1 % 0.77 0.30 0.484
Sensitive τ = 0.50 84.8 % 0.18 0.88 0.484
  • PR-AUC 0.484 vs. a random baseline of 0.037 (≈ 13×).
  • At the tuned point: specificity 99.7 %, MCC 0.47.
  • For gradual events the mean predicted probability crosses the 0.67 alert threshold ≈ 13 min before onset (10–15 min depending on the event; P ≈ 0.70 at 10 min). Sudden events have no precursor and are not predictable from local voltage — that is the edge tree's job.

Prediction lead time Top XGBoost features

Quick start

A. Demo without hardware (≈ 5 min)

git clone https://github.com/rafiul254/EdgeVolt.git && cd EdgeVolt
python -m venv .venv && source .venv/bin/activate        # Windows: .venv\Scripts\activate
pip install -r requirements.txt

uvicorn backend.main:app --port 8000                      # terminal 1 (falls back to the bundled CSV)
streamlit run dashboard/app.py                            # terminal 2 -> http://localhost:8501

Replay demo: Prediction tab → replay at 2026-10-30 20:41:00 → P ≈ 0.72, ALERT, ≈ 15 min before the simulated outage at 20:56 (voltage already sagging at ≈ 213 V).

curl "http://localhost:8000/predict/node1?at=2026-10-30T20:41:00"
B. Full stack with hardware
docker compose up -d                       # Mosquitto :1883 + InfluxDB :8086
cp firmware/include/secrets.example.h firmware/include/secrets.h   # then edit WiFi + MQTT_HOST (LAN IP, not localhost)
cd firmware && pio run -t upload && pio device monitor             # 1 Hz "V=… I=… f=…" lines
python backend/mqtt_subscriber.py          # MQTT -> InfluxDB
uvicorn backend.main:app --port 8000 &
streamlit run dashboard/app.py

⚠️ docker-compose.yml ships development credentials (edgevolt123, edgevolt-token-123456) and Mosquitto allows anonymous access. Change them (and enable MQTT auth/TLS) before exposing anything beyond your LAN. Backend settings can be overridden with INFLUX_URL, INFLUX_TOKEN, INFLUX_ORG, INFLUX_BUCKET, MQTT_HOST, MQTT_PORT.

C. Retrain (works on real data unchanged)
python ml/make_synthetic.py      # or place a real 1-min CSV in ml/data/
python ml/train_xgboost.py       # -> ml/metrics.json, ml/deploy_config.json, model files
python ml/train_edge_tree.py     # -> edge_tree.txt (copy thresholds into firmware)

REST API

Endpoint Description
GET /health Service, model and database status
GET /nodes Known nodes
GET /latest/{node} Latest reading
GET /history/{node}?mins= Recent history
GET /predict/{node}[?at=ISO-time] 30-min outage probability (at = replay)
GET /cost/{node}?tariff=7 Estimated outage cost in BDT

Repository structure

EdgeVolt/
├── firmware/            ESP32 PlatformIO project (include/secrets.example.h)
├── backend/             FastAPI service + MQTT→InfluxDB subscriber
├── dashboard/           Streamlit app (5 tabs, demo mode)
├── ml/                  benchmark generator, features_1min, XGBoost + edge-tree training
├── data/                raw/ processed/ (git-ignored) and a small sample
├── docs/                HARDWARE.md, ROADMAP.md, images (banner, prototype, poster)
├── figures/             result figures used in this README
├── mosquitto/           broker config
├── report/              IEEE-style progress report (LaTeX source)
├── legacy/              superseded first-build files (not used)
├── tests/               API smoke tests (pytest)
└── docker-compose.yml   Mosquitto + InfluxDB 2.7

Roadmap

  • Edge firmware, backend, dashboard, leakage-safe ML pipeline
  • Hardware prototype assembled
  • Calibrate the node (voltage factor, current noise floor) against a reference meter
  • Collect ~1 month of live 1 Hz data with labelled load-shedding events
  • Retrain on real data, compare against a time-of-day baseline, report event-level metrics
  • Hardening: NTP timestamps, flash buffering during outages, MQTT auth/TLS, enclosed fused mains adapter
  • Multi-node deployment and feeder-level correlation

Limitations

  • All ML results are from a simulated benchmark. The 65 % gradual-onset share is an assumption of the simulator; real grids may differ.
  • Single node; no feeder-level spatial correlation yet.
  • Apparent power (VA) only — power factor is not measured; cost estimates use VA as an upper bound.
  • Sudden outages without a voltage precursor cannot be forecast from local measurements.
  • Voltage path needs a one-time VOLTAGE_CAL; the cost-model parameters are placeholders to be refined with real surveys.

Safety

⚠️ This project connects to 220–240 V mains.

Do not push bare wires into a multiplug or breadboard mains. Keep all mains-side connections insulated, fused and fully enclosed; keep the low-voltage breadboard physically separate; never touch the circuit while energised; clamp the CT around one insulated conductor only, never by cutting a live wire. If you are unsure, have a qualified electrician build and inspect the mains adapter. Provided for education and research, without warranty.

Authors, citation, license

👥 Team

Md. Rafiul Islam Lead developer — firmware, backend, ML pipeline, dashboard, hardware prototype · @rafiul254
Sabiha Binte Hasnat Co-author
Tajnin Tarin Tonni Co-author
Saurav Chandra Das Supervisor

Department of Internet of Things and Robotics Engineering, University of Frontier Technology, Bangladesh (UFTB), Kaliakair, Gazipur

📎 Cite this work

@misc{edgevolt2026,
  title  = {EdgeVolt: Edge-Intelligent Load-Shedding Prediction and Real-Time Power-Quality Monitoring},
  author = {Md. Rafiul Islam},
  year   = {2026},
  note   = {Extended abstract, IEEE Computer Society Bangladesh Chapter Symposium 2026},
  url    = {https://github.com/rafiul254/EdgeVolt}
}

Released under the MIT License. Questions or ideas? Open a GitHub Issue.


Animated tagline

⭐ If EdgeVolt helps you, consider starring the repo! ⭐

EdgeVolt animated footer

About

Edge-Intelligent Load Shedding Prediction and Real-Time Monitoring System for Bangladesh Micro-Level Distribution Grids.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Contributors

Languages