Smart Energy Monitoring Platform for Rural India
Real-time insights · AI-powered anomaly detection · Multilingual support
Gram Meter is a full-stack smart energy monitoring platform built for rural communities in India. It connects IoT smart meters to an AI-powered backend that provides real-time energy monitoring, anomaly detection, billing, and insights — all in local languages.
Built for Square Hacks Hackathon.
┌─────────────────┐ MQTT ┌──────────────────┐
│ Virtual Meter │─────────────▶│ MQTT Broker │
│ (IoT Sim) │ │ (HiveMQ) │
└─────────────────┘ └────────┬─────────┘
│
┌───────────▼──────────┐
│ Django Backend │
│ (REST API + WS) │
│ Port: 8000 │
└───────────┬──────────┘
│
┌─────────────────────▼─────────────────┐
│ FastAPI ML Gateway │
│ Forecast · Anomaly · Efficiency │
│ Port: 8001 │
└─────────────────────┬─────────────────┘
│
┌───────────▼──────────┐
│ React Frontend │
│ (Vite + Tailwind) │
│ Port: 5173 │
└──────────────────────┘
| Feature | Description |
|---|---|
| 📡 Real-time Monitoring | Live meter readings via WebSockets and MQTT |
| 🤖 AI Anomaly Detection | Detects voltage spikes, drops, overcurrent & phantom loads |
| 📈 Energy Forecasting | 24-hour predictions with confidence intervals |
| 🏆 Efficiency Scoring | 0–100 score with actionable recommendations |
| 💸 Smart Billing | Auto-generated bills with tariff rate management |
| 🌐 Multilingual | Full support for English, Hindi (हिंदी), and Gujarati (ગુજરાતી) |
| 🔐 JWT + 2FA Auth | Secure role-based access (Farmer, Sarpanch, Utility, Government) |
| 🗺️ Admin Console | Government panel with live village map visualization |
| 📊 Analytics Engine | Historical trends, usage patterns, cost savings reports |
gram-meter/
├── backend/ # Django REST API + FastAPI ML Gateway
│ ├── meters/ # Core meters app (models, views, WebSockets)
│ ├── analytics/ # Forecasting & pattern analysis
│ ├── billing/ # Invoices & tariff management
│ ├── ml_gateway/ # FastAPI ML microservice
│ └── scripts/ # Sample data & live data generator
│
├── frontend/ # React + Vite frontend
│ └── src/
│ ├── components/ # Reusable UI components
│ ├── pages/ # Dashboard, Billing, Analytics, etc.
│ ├── contexts/ # Language, Theme, Translation providers
│ └── services/ # API & auth service layer
│
├── ML/ # Machine learning models & training
│ ├── model_trainer.py # Train forecast & anomaly models
│ ├── virtual_meter.py # IoT meter simulator (MQTT publisher)
│ ├── analytics_engine.py
│ └── mqtt_listner.py
│
├── Admin console/ # Government admin panel (React)
│
├── start_platform.sh # One-command startup (macOS/Linux)
└── start_platform.bat # One-command startup (Windows)
- Python 3.10+
- Node.js 18+
- pip
git clone https://github.com/Jaimin2687/gram-meter.git
cd gram-metercd backend
python -m venv ../.venv
source ../.venv/bin/activate # Windows: ..\.venv\Scripts\activate
pip install -r requirements.txt
# Apply migrations & seed sample data
python manage.py migrate
python scripts/populate_sample_data.pycd frontend
npm installmacOS / Linux:
chmod +x start_platform.sh
./start_platform.shWindows:
start_platform.batOr manually:
# Terminal 1 — Django API
source .venv/bin/activate && cd backend && python manage.py runserver
# Terminal 2 — FastAPI ML Gateway
source .venv/bin/activate && cd backend && uvicorn ml_gateway.main:app --reload --port 8001
# Terminal 3 — React Frontend
cd frontend && npm run dev
# Terminal 4 — Virtual IoT Meter (optional)
source .venv/bin/activate && cd ML && python virtual_meter.py| Service | URL |
|---|---|
| React Frontend | http://localhost:5173 |
| Django REST API | http://localhost:8000/api/v1/ |
| API Docs (Swagger) | http://localhost:8000/swagger/ |
| FastAPI ML Gateway | http://localhost:8001 |
| ML Docs | http://localhost:8001/docs |
| Username | Password | Role |
|---|---|---|
farmer_ramesh |
password123 |
Farmer |
farmer_priya |
password123 |
Farmer |
sarpanch_kumar |
password123 |
Sarpanch |
Automatically detects:
- ⚡ Voltage spikes / drops
- 🔴 Overcurrent faults
- 👻 Phantom loads (energy theft)
- 🌑 Power outages
- 24-hour prediction window
- Confidence intervals (upper/lower bounds)
- Powered by trained
forecast_model(MQTT-collected data)
Grades each meter on:
- Power factor performance
- Load profile consistency
- Peak usage patterns
- Monthly trends
Note: Large ML model files (
forecast_model.pkl,anomaly_model.pkl) are excluded from this repo due to GitHub's 100MB file limit. RunML/model_trainer.pyto regenerate them locally.
POST /api/v1/auth/login/ → Get JWT token
GET /api/v1/dashboard/stats/ → Dashboard summary
GET /api/v1/meters/ → List all meters
GET /api/v1/meters/{id}/readings/ → Historical readings
GET /api/v1/meters/{id}/live_status/ → Real-time status
GET /api/v1/alerts/ → Active alerts
GET /api/v1/billing/invoices/ → Bills & invoices
POST /api/v1/anomaly/detect → Run anomaly detection (ML)
POST /api/v1/forecast/predict → Energy forecast (ML)
WebSocket endpoints:
ws://localhost:8000/ws/meters/{id}/ → Live meter stream
ws://localhost:8000/ws/dashboard/ → Dashboard updates
ws://localhost:8000/ws/alerts/ → Real-time alerts
| Layer | Technology |
|---|---|
| Frontend | React 18, Vite, Tailwind CSS |
| Backend API | Django 5, Django REST Framework |
| ML Service | FastAPI, scikit-learn |
| Auth | JWT (SimpleJWT) + 2FA |
| Real-time | Django Channels (WebSocket), Redis |
| IoT | MQTT (paho-mqtt, HiveMQ broker) |
| Database | SQLite (dev) / PostgreSQL-ready |
| ML/Data | pandas, scikit-learn, numpy |
Port already in use:
lsof -ti:8000 | xargs kill -9
lsof -ti:8001 | xargs kill -9Database reset:
cd backend
rm db.sqlite3
python manage.py migrate
python scripts/populate_sample_data.pyVirtual environment issues:
python -m venv .venv
source .venv/bin/activate
pip install -r backend/requirements.txtThis project was built for Square Hacks 2025.
Built with ❤️ for Rural India