Skip to content

Bavan2002/EcoWatt_TeamPowerPort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

312 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒฑ EcoWatt - Smart Inverter Monitoring System

Team PowerPort | EN4440 Embedded Systems and Design
University of Moratuwa | Department of Electronic and Telecommunication Engineering

Compression FOTA Security Power ESP32 Python React

Features โ€ข Quick Start โ€ข Architecture โ€ข Documentation โ€ข Team


๐Ÿ“‹ Overview

EcoWatt is an IoT system for real-time monitoring and intelligent control of solar inverters. Built on ESP32 hardware with secure cloud connectivity, the system features adaptive data compression, secure FOTA updates, and intelligent power management for extended battery life.

Note: This implementation uses a simulated inverter over WiFi for development and testing. Production deployment would use Modbus RTU for communication with physical inverters.

Project Highlights

  • Adaptive Compression: Dictionary-based compression achieves up to 85% reduction for repetitive data patterns
  • Military-Grade Security: Triple-layer upload protection with RSA-2048 signed firmware updates
  • Power Optimization: Peripheral gating strategy for reduced power consumption
  • Remote Configuration: Bidirectional command system for device management
  • Professional Dashboard: React-based monitoring interface with live data visualization
  • Comprehensive Testing: 30+ test suites covering all major components

Key Features

Security Architecture

  • Triple-Layer Upload Protection
    • Anti-replay nonce validation
    • HMAC-SHA256 authentication
    • AES-128-CBC encryption support
  • Secure FOTA Updates
    • AES-256-CBC encrypted firmware
    • RSA-2048 digital signatures
    • Automatic rollback protection

Data Compression

  • Adaptive Algorithm Selection
    • Dictionary compression (up to 85%)
    • Temporal delta encoding (~65%)
    • Semantic RLE (~55%)
    • Bit-packing fallback (~40%)
  • Automatic best-fit selection

Power Management

  • Peripheral Gating (Current Implementation)
    • UART/Modbus transceiver gating
    • Configurable duty cycle
  • Future Production Features
    • CPU frequency scaling
    • Light sleep modes
    • Deep sleep for battery operation

Remote Configuration

  • Bidirectional Communication
    • Command queue system
    • Parameter configuration
    • Real-time status feedback
  • Device Management
    • Polling interval adjustment
    • Compression settings
    • Security parameters

๐Ÿš€ Quick Start

Prerequisites

Component Version Purpose
Python 3.10+ Flask backend server
Node.js 20+ React frontend
PlatformIO Latest ESP32 firmware development
Just Latest Task automation (recommended)

โšก One-Command Setup

# Complete first-time setup (installs all dependencies)
just setup

# Verify installation
just status

๐ŸŽฎ Quick Commands

# Backend
just s              # Start Flask server (localhost:5001)

# Frontend  
just d              # Start React dev server (localhost:5173)

# ESP32
just f              # Flash firmware
just m              # Monitor serial output
just fm             # Flash + monitor

# Testing
just test-all       # Run all test suites

๐Ÿ—๏ธ System Architecture

graph TB
    subgraph "Edge Device"
        A[Solar Inverter] -->|Modbus RTU<br/>2s poll| B[ESP32 EcoWatt]
    end
    
    subgraph "Cloud Backend"
        B -->|HTTPS<br/>Compressed + Secured| C[Flask Server]
        C -->|Store| D[(SQLite DB)]
        C -->|Publish| E[MQTT Broker]
    end
    
    subgraph "Web Interface"
        C -->|REST API| F[React Dashboard]
        E -->|WebSocket| F
    end
    
    style B fill:#4CAF50,stroke:#2E7D32,stroke-width:2px
    style C fill:#2196F3,stroke:#1565C0,stroke-width:2px
    style F fill:#FF9800,stroke:#E65100,stroke-width:2px
Loading

๐Ÿ”„ Data Flow Pipeline

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Modbus    โ”‚ -> โ”‚ Ring Buffer  โ”‚ -> โ”‚ Compression โ”‚ -> โ”‚   Security   โ”‚
โ”‚   2s Poll   โ”‚    โ”‚  7 Samples   โ”‚    โ”‚   96.4%     โ”‚    โ”‚ Nonce + HMAC โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                                    |
                                                                    v
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   MQTT      โ”‚ <- โ”‚   Database   โ”‚ <- โ”‚   Validate  โ”‚ <- โ”‚ HTTPS Upload โ”‚
โ”‚  Publish    โ”‚    โ”‚    Store     โ”‚    โ”‚  Decompress โ”‚    โ”‚  15s Batch   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Web Dashboard

Dashboard Screenshots

Live Dashboard Power Management
Dashboard Power
Real-time metrics and data visualization Energy analytics and optimization
Device Configuration FOTA Updates
Configuration FOTA
Remote settings and parameter control Secure firmware deployment
System Testing
Testing
Comprehensive fault injection and diagnostics

Dashboard Capabilities

  • Live Data Visualization: Real-time charts for voltage, current, power, and temperature
  • Power Analytics: Energy consumption tracking and optimization metrics
  • Remote Configuration: Adjust polling intervals, compression settings, and security parameters
  • OTA Management: Deploy firmware updates with progress monitoring
  • Fault Injection: Test system resilience with built-in diagnostic tools
  • Device Status: Monitor connection health, WiFi signal, and error logs

๐Ÿ“‚ Project Structure

EcoWatt_TeamPowerPort/
โ”œโ”€โ”€ ๐Ÿ”ง PIO/ECOWATT/                 # ESP32 Firmware (C++)
โ”‚   โ”œโ”€โ”€ src/                        # Source code
โ”‚   โ”‚   โ”œโ”€โ”€ main.cpp               # Petri net state machine
โ”‚   โ”‚   โ””โ”€โ”€ application/           # Core modules
โ”‚   โ”œโ”€โ”€ include/                   # Header files
โ”‚   โ”œโ”€โ”€ test/                      # Unit & integration tests
โ”‚   โ””โ”€โ”€ platformio.ini             # Build configuration
โ”‚
โ”œโ”€โ”€ ๐Ÿ flask/                       # Flask Backend (Python)
โ”‚   โ”œโ”€โ”€ handlers/                  # Business logic
โ”‚   โ”œโ”€โ”€ routes/                    # API endpoints
โ”‚   โ”œโ”€โ”€ scripts/                   # Utility scripts
โ”‚   โ”œโ”€โ”€ firmware/                  # OTA firmware storage
โ”‚   โ””โ”€โ”€ flask_server_modular.py    # Main entry point
โ”‚
โ”œโ”€โ”€ โš›๏ธ front-end/                   # React Dashboard (JavaScript)
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/            # UI components
โ”‚   โ”‚   โ”œโ”€โ”€ pages/                 # Page layouts
โ”‚   โ”‚   โ””โ”€โ”€ api/                   # API integration
โ”‚   โ””โ”€โ”€ package.json
โ”‚
โ”œโ”€โ”€ ๐Ÿ“š docs/                        # Documentation
โ”œโ”€โ”€ ๐Ÿ–ผ๏ธ images/                      # Screenshots & diagrams
โ””โ”€โ”€ justfile                       # Task automation

๐Ÿ› ๏ธ Technology Stack

ESP32 Firmware

Language: C++ (Arduino)
Build: PlatformIO
Security: mbedTLS
Protocols: Modbus RTU, HTTPS
Testing: Unity Framework

Flask Backend

Language: Python 3.10+
Framework: Flask + CORS
Security: Cryptography lib
Database: SQLite
Messaging: Paho-MQTT
Testing: Pytest

React Frontend

Framework: React 18
Build: Vite
UI: Material-UI (MUI)
Data: React Query
Charts: Recharts
HTTP: Axios


Performance Metrics

Metric Value Note
Compression Ratio Up to 85% (140 โ†’ 21 bytes) Dictionary method, typical patterns
Upload Interval 15 seconds (default) Configurable
Poll Rate 2 seconds (default) Configurable: WiFi simulation
FOTA Chunk Size 2 KB Memory-efficient streaming
Power Savings Peripheral gating only 10% duty cycle (simulation mode)
Security Level HMAC-SHA256 + RSA-2048 Production-grade cryptography
Command Latency < 1 second Network dependent
Test Coverage 30+ test suites ESP32, Backend, Integration

Note on Performance: Current metrics are based on simulated inverter implementation using WiFi polling. Production deployment with Modbus RTU communication will enable additional power-saving features including CPU frequency scaling and sleep modes.


๐Ÿงช Testing

The project includes 30+ comprehensive test suites:

ESP32 Tests

  • โœ… Compression algorithms
  • โœ… Security functions
  • โœ… OTA components
  • โœ… Modbus drivers
  • โœ… M3/M4 integration

Backend Tests

  • โœ… Flask handlers
  • โœ… API routes
  • โœ… Decompression logic
  • โœ… Security validation
  • โœ… Database operations

System Tests

  • โœ… End-to-end workflows
  • โœ… Fault injection
  • โœ… Network failures
  • โœ… Rollback scenarios
  • โœ… Performance benchmarks
just test-all       # Run all test suites

Documentation

Comprehensive documentation is available in the docs/ directory:

Document Description
Features Guide In-depth feature explanations with examples
Architecture System design, data flows, and state machines
Security Guide Cryptographic implementations and threat model
Implementation Notes Simulation vs production architecture
Setup Guide Detailed installation and configuration
API Reference Complete REST API documentation

Quick Links

Documentation Setup Guide API Reference Architecture

Version 1.3.5 | Last Updated: December 12, 2024

โญ If you found this project interesting, please consider giving it a star!

About

No description, website, or topics provided.

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors