# nagatarafi/iot-power-monitoring-lorawan architecture

> Architecture diagram of the GitHub repository nagatarafi/iot-power-monitoring-lorawan, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nagatarafi/iot-power-monitoring-lorawan
- Repository: https://github.com/nagatarafi/iot-power-monitoring-lorawan

## Overview

This repository implements an ESP32-based, three-phase electrical monitoring system. Its principal workflow reads PZEM measurements, encodes them for LoRaWAN OTAA, and sends them through a gateway to a backend for storage, dashboards, and notifications. The README documents the wider gateway and backend architecture; their implementation is not present in the sampled source, so those components are shown as documented external services. The firmware path is supported by the tree, but its sketch source was not sampled.

Main entry points: [`power_monitoring_3phase_lora__5_/power_monitoring_3phase_lora__5_.ino`](https://github.com/nagatarafi/iot-power-monitoring-lorawan/blob/main/power_monitoring_3phase_lora__5_/power_monitoring_3phase_lora__5_.ino) (ESP32 monitoring node), [`lmic_project_config.h`](https://github.com/nagatarafi/iot-power-monitoring-lorawan/blob/main/lmic_project_config.h) (LMIC radio config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["Sensor firmware"]
  node_firmware["ESP32 monitoring node"]
  node_config["LMIC radio config"]
  node_encoder["Payload encoding"]
  node_lmic["LMIC OTAA"]
end

subgraph group_network["LoRaWAN transport"]
  node_gateway["WM1302 gateway"]
  node_chirpstack["ChirpStack"]
  node_mqtt["Mosquitto MQTT"]
end

subgraph group_processing["Data processing"]
  node_nodered["Node-RED processing"]
  node_influx[("InfluxDB")]
end

subgraph group_outputs["Monitoring outputs"]
  node_apps_script["Apps Script integration"]
  node_sheets[("Google Sheets")]
  node_grafana["Grafana dashboards"]
  node_web["Web dashboard"]
  node_telegram["Telegram bot"]
end

node_pzem(("PZEM sensors"))

node_pzem -->|"provides readings"| node_firmware
node_firmware -->|"encodes measurements"| node_encoder
node_firmware -->|"queues uplink"| node_lmic
node_config -->|"configures radio"| node_lmic
node_lmic -->|"sends LoRaWAN"| node_gateway
node_gateway -->|"forwards packets"| node_chirpstack
node_chirpstack -->|"publishes events"| node_mqtt
node_mqtt -->|"dispatches events"| node_nodered
node_nodered -->|"writes measurements"| node_influx
node_influx -->|"serves queries"| node_grafana
node_grafana -->|"renders dashboards"| node_web
node_mqtt -.->|"dispatches events"| node_apps_script
node_apps_script -.->|"writes rows"| node_sheets
node_mqtt -.->|"dispatches alerts"| node_telegram

click node_firmware "https://github.com/nagatarafi/iot-power-monitoring-lorawan/blob/main/power_monitoring_3phase_lora__5_/power_monitoring_3phase_lora__5_.ino"
click node_config "https://github.com/nagatarafi/iot-power-monitoring-lorawan/blob/main/lmic_project_config.h"
click node_encoder "https://github.com/nagatarafi/iot-power-monitoring-lorawan/blob/main/power_monitoring_3phase_lora__5_/power_monitoring_3phase_lora__5_.ino"
click node_lmic "https://github.com/nagatarafi/iot-power-monitoring-lorawan/blob/main/power_monitoring_3phase_lora__5_/power_monitoring_3phase_lora__5_.ino"

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_firmware,node_config,node_encoder,node_lmic toneBlue
class node_gateway,node_chirpstack,node_mqtt toneAmber
class node_nodered,node_influx toneMint
class node_apps_script,node_sheets,node_grafana,node_web,node_telegram toneRose
class node_pzem toneIndigo
```

## Components

### Sensor firmware

- [ESP32 monitoring node](https://github.com/nagatarafi/iot-power-monitoring-lorawan/blob/main/power_monitoring_3phase_lora__5_/power_monitoring_3phase_lora__5_.ino): `power_monitoring_3phase_lora__5_/power_monitoring_3phase_lora__5_.ino`
- [LMIC radio config](https://github.com/nagatarafi/iot-power-monitoring-lorawan/blob/main/lmic_project_config.h): `lmic_project_config.h`
- [Payload encoding](https://github.com/nagatarafi/iot-power-monitoring-lorawan/blob/main/power_monitoring_3phase_lora__5_/power_monitoring_3phase_lora__5_.ino): `power_monitoring_3phase_lora__5_/power_monitoring_3phase_lora__5_.ino`
- [LMIC OTAA](https://github.com/nagatarafi/iot-power-monitoring-lorawan/blob/main/power_monitoring_3phase_lora__5_/power_monitoring_3phase_lora__5_.ino): `power_monitoring_3phase_lora__5_/power_monitoring_3phase_lora__5_.ino`

### LoRaWAN transport

- **WM1302 gateway**
- **ChirpStack**
- **Mosquitto MQTT**

### Data processing

- **Node-RED processing**
- **InfluxDB**

### Monitoring outputs

- **Apps Script integration**
- **Google Sheets**
- **Grafana dashboards**
- **Web dashboard**
- **Telegram bot**

### Other components

- **PZEM sensors**

## Connections

- PZEM sensors → ESP32 monitoring node: provides readings
- ESP32 monitoring node → Payload encoding: encodes measurements
- ESP32 monitoring node → LMIC OTAA: queues uplink
- LMIC radio config → LMIC OTAA: configures radio
- LMIC OTAA → WM1302 gateway: sends LoRaWAN
- WM1302 gateway → ChirpStack: forwards packets
- ChirpStack → Mosquitto MQTT: publishes events
- Mosquitto MQTT → Node-RED processing: dispatches events
- Node-RED processing → InfluxDB: writes measurements
- InfluxDB → Grafana dashboards: serves queries
- Grafana dashboards → Web dashboard: renders dashboards
- Mosquitto MQTT → Apps Script integration: dispatches events
- Apps Script integration → Google Sheets: writes rows
- Mosquitto MQTT → Telegram bot: dispatches alerts
