How h3xb1n/iot-based-smart-energy-meter works
Project type and purpose
• This is a full-stack Django web application (“IoT Based Smart Energy Meter”) that:
• Receives live power-usage data from an external IoT device (Arduino Uno + current sensors + ESP8266)
• Stores and manages that data in a relational database
• Presents charts, day-/month-wise views, and downloadable Excel reports via a web UI
File structure
• sem_project/ – Django project settings, URL routing, WSGI entrypoint
• api/ – Django REST Framework app handling JSON endpoints for IoT data ingestion and possibly chart data
• pages/ – Django app rendering HTML pages (home, headers, charts), resources for Excel export
• users/ – Authentication/registration: models, forms, views, URLs
• templates/ – HTML templates plus embedded JavaScript/CSS (jQuery UI) for client-side charting
• db.sqlite3 – development database
• Pipfile & Pipfile.lock – Python dependency management
Key insights from README
• Data flow: Arduino Uno → computes power usage → ESP8266 sends HTTP requests → Django API → DB
• Web UI polls or fetches latest DB records to plot charts in real time
• Excel export via a Django view
Main components
A. IoT Device Layer
• Arduino Uno + Current Sensor hardware
• ESP8266 Wi-Fi module
B. Web Server / Application Layer (Django Monolith)
• WSGI server (Gunicorn/UWSGI, implicit)
• Django core (settings, URL router)
• Sub-apps:
– api app (views → serializers → models)
– pages app (views/templates → chart rendering & Excel generation)
– users app (authentication, forms, user profile)
C. Database Layer
• SQLite (or equivalent RDBMS in production)
D. Client Layer
• Browser (HTML/CSS/JavaScript – jQuery UI, chart library)
Relationships & interactions
1. IoT Device → HTTP POST → api/data-ingest endpoint → Django api.views
2. api.views → validate via serializers → write to DB
3. Browser → HTTP GET → pages/home endpoint → Django pages.views → render templates
4. Browser JavaScript → AJAX GET → api/chart-data endpoint → JSON from api.serializers
5. Browser → click “Download Excel” → pages/resources view → generate and stream .xlsx from DB
6. Users app mediates login/signup → grants access to pages
Architectural patterns & design principles
• Monolithic MVC (Django)
• RESTful API for IoT ingestion and data retrieval
• Template-driven server-side rendering plus client-side AJAX chart updates
• Clear separation of concerns via distinct Django apps