# techsmithlab/embedded-iot-energy-monitoring-esp32 architecture

> Architecture diagram of the GitHub repository techsmithlab/embedded-iot-energy-monitoring-esp32, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/techsmithlab/embedded-iot-energy-monitoring-esp32
- Repository: https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32

## Overview

This is an ESP32 smart-energy monitor and load controller. Its principal workflow samples AC voltage and current, calibrates and converts them to RMS readings, derives apparent power, accumulates energy, then presents readings locally and uploads telemetry over Wi-Fi; relay control is an additional load-control capability. The graph preserves calibration, persistence, and both cloud options. The main sketch is present in the tree but was not excerpted, so orchestration edges follow the README’s documented workflow rather than claims about unsampled calls.

Main entry points: [`firmware/smart_energy_monitor/smart_energy_monitor.ino`](https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/smart_energy_monitor.ino) (Firmware workflow), [`firmware/smart_energy_monitor/cloud.cpp`](https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/cloud.cpp) (Cloud telemetry), [`firmware/smart_energy_monitor/sensors.cpp`](https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/sensors.cpp) (Sensor acquisition), [`firmware/smart_energy_monitor/calibration.cpp`](https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/calibration.cpp) (Calibration routine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_measurement["Measurement"]
  node_sensors["Sensor acquisition<br/>[sensors.cpp]"]
  node_calibration["Calibration routine<br/>[calibration.cpp]"]
end

subgraph group_processing["Processing"]
  node_main_firmware["Firmware workflow"]
  node_energy["Energy accumulation<br/>[energy.cpp]"]
  node_nvs[("ESP32 NVS")]
end

subgraph group_device_io["Device I/O"]
  node_lcd["LCD display<br/>[display.cpp]"]
  node_lcd_hardware["I2C LCD"]
  node_relay_control["Relay control<br/>[relay_control.cpp]"]
  node_load["Connected load"]
end

subgraph group_connectivity["Connectivity"]
  node_wifi_manager["Wi-Fi manager<br/>[wifi_manager.cpp]"]
  node_wifi_network["Wi-Fi network"]
  node_cloud["Cloud telemetry<br/>[cloud.cpp]"]
  node_thingspeak["ThingSpeak"]
  node_blynk["Blynk"]
end

node_ac_system(("AC system"))
node_serial_user(("Serial operator"))

node_ac_system -->|"provides signals"| node_sensors
node_main_firmware -->|"reads measurements"| node_sensors
node_main_firmware -->|"updates energy"| node_energy
node_sensors -->|"measures offsets"| node_calibration
node_main_firmware -->|"runs calibration"| node_calibration
node_energy -->|"persists energy"| node_nvs
node_main_firmware -->|"shows readings"| node_lcd
node_lcd -->|"writes display"| node_lcd_hardware
node_main_firmware -->|"controls relay"| node_relay_control
node_relay_control -->|"switches load"| node_load
node_main_firmware -->|"manages connection"| node_wifi_manager
node_wifi_manager -->|"connects to"| node_wifi_network
node_main_firmware -->|"uploads telemetry"| node_cloud
node_cloud -->|"checks connection"| node_wifi_network
node_cloud -->|"sends HTTP update"| node_thingspeak
node_cloud -.->|"runs integration"| node_blynk
node_serial_user -.->|"starts routine"| node_calibration

click node_sensors "https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/sensors.cpp"
click node_calibration "https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/calibration.cpp"
click node_main_firmware "https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/smart_energy_monitor.ino"
click node_energy "https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/energy.cpp"
click node_lcd "https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/display.cpp"
click node_relay_control "https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/relay_control.cpp"
click node_wifi_manager "https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/wifi_manager.cpp"
click node_cloud "https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/cloud.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sensors,node_calibration toneBlue
class node_main_firmware,node_energy,node_nvs toneAmber
class node_lcd,node_lcd_hardware,node_relay_control,node_load toneMint
class node_wifi_manager,node_wifi_network,node_cloud,node_thingspeak,node_blynk toneRose
class node_ac_system,node_serial_user toneIndigo
```

## Components

### Measurement

- [Sensor acquisition](https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/sensors.cpp): `firmware/smart_energy_monitor/sensors.cpp`
- [Calibration routine](https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/calibration.cpp): `firmware/smart_energy_monitor/calibration.cpp`

### Processing

- [Firmware workflow](https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/smart_energy_monitor.ino): `firmware/smart_energy_monitor/smart_energy_monitor.ino`
- [Energy accumulation](https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/energy.cpp): `firmware/smart_energy_monitor/energy.cpp`
- **ESP32 NVS**

### Device I/O

- [LCD display](https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/display.cpp): `firmware/smart_energy_monitor/display.cpp`
- **I2C LCD**
- [Relay control](https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/relay_control.cpp): `firmware/smart_energy_monitor/relay_control.cpp`
- **Connected load**

### Connectivity

- [Wi-Fi manager](https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/wifi_manager.cpp): `firmware/smart_energy_monitor/wifi_manager.cpp`
- **Wi-Fi network**
- [Cloud telemetry](https://github.com/techsmithlab/embedded-iot-energy-monitoring-esp32/blob/main/firmware/smart_energy_monitor/cloud.cpp): `firmware/smart_energy_monitor/cloud.cpp`
- **ThingSpeak**
- **Blynk**

### Other components

- **AC system**
- **Serial operator**

## Connections

- AC system → Sensor acquisition: provides signals (evidence: `README.md`)
- Firmware workflow → Sensor acquisition: reads measurements (evidence: `README.md`)
- Firmware workflow → Energy accumulation: updates energy (evidence: `README.md`)
- Sensor acquisition → Calibration routine: measures offsets (evidence: `firmware/smart_energy_monitor/calibration.cpp`)
- Firmware workflow → Calibration routine: runs calibration (evidence: `README.md`)
- Energy accumulation → ESP32 NVS: persists energy (evidence: `firmware/smart_energy_monitor/energy.cpp`)
- Firmware workflow → LCD display: shows readings (evidence: `README.md`)
- LCD display → I2C LCD: writes display (evidence: `firmware/smart_energy_monitor/display.cpp`)
- Firmware workflow → Relay control: controls relay (evidence: `README.md`)
- Relay control → Connected load: switches load (evidence: `README.md`)
- Firmware workflow → Wi-Fi manager: manages connection (evidence: `README.md`)
- Wi-Fi manager → Wi-Fi network: connects to (evidence: `firmware/smart_energy_monitor/wifi_manager.cpp`)
- Firmware workflow → Cloud telemetry: uploads telemetry (evidence: `README.md`)
- Cloud telemetry → Wi-Fi network: checks connection (evidence: `firmware/smart_energy_monitor/cloud.cpp`)
- Cloud telemetry → ThingSpeak: sends HTTP update (evidence: `firmware/smart_energy_monitor/cloud.cpp`)
- Cloud telemetry → Blynk: runs integration (evidence: `firmware/smart_energy_monitor/cloud.cpp`)
- Serial operator → Calibration routine: starts routine
