# servayejc/esp8266_espnow architecture

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

- Interactive diagram: https://gitdiagram.com/servayejc/esp8266_espnow
- Repository: https://github.com/servayejc/esp8266_espnow

## Overview

This is ESP8266 firmware for a wireless temperature-monitoring and thermostat node. At startup it restores persistent settings, initializes ESP-NOW, discovers 1-Wire sensors, and then pairs with a server; while paired, it reads temperatures, applies thermostat setpoints, controls outputs, and sends device data. Incoming setpoints are handled by the registered receive callback. The graph follows the sampled source; the README is empty, and hardware and server-side behavior are represented only where the excerpts show an interface.

Main entry points: [`src/main.cpp`](https://github.com/servayejc/esp8266_espnow/blob/master/src/main.cpp) (ESP8266 node), [`src/esp_now_pairing.cpp`](https://github.com/servayejc/esp8266_espnow/blob/master/src/esp_now_pairing.cpp) (ESP-NOW pairing), [`src/Temperatures.cpp`](https://github.com/servayejc/esp8266_espnow/blob/master/src/Temperatures.cpp) (Sensor discovery and readings), [`src/Utils.cpp`](https://github.com/servayejc/esp8266_espnow/blob/master/src/Utils.cpp) (Settings persistence)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Firmware runtime"]
  node_device["ESP8266 node<br/>[main.cpp]"]
end

subgraph group_wireless["Wireless pairing"]
  node_pairing["ESP-NOW pairing"]
end

subgraph group_sensing["Temperature sensing"]
  node_sensor_manager["Sensor discovery and readings<br/>[Temperatures.cpp]"]
end

subgraph group_control["Control and state"]
  node_device_state["Device state and messages<br/>[global.h]"]
  node_control_logic["Thermostat output control<br/>[Control.cpp]"]
  node_persistence["Settings persistence<br/>[Utils.cpp]"]
  node_eeprom[("EEPROM")]
end

node_server(("Pairing server"))
node_espnow_service["ESP-NOW service"]
node_onewire["1-Wire sensors"]
node_i2c_expander["I2C output expander"]
node_device_gpio["ESP8266 GPIO"]

node_device -->|"restores settings"| node_persistence
node_device -->|"initializes radio"| node_pairing
node_device -->|"discovers sensors"| node_sensor_manager
node_device -->|"checks pairing"| node_pairing
node_device -->|"requests readings"| node_sensor_manager
node_device -->|"uses message state"| node_device_state
node_pairing -->|"requests pairing"| node_server
node_server -->|"provides pairing data"| node_pairing
node_pairing -->|"registers callbacks"| node_espnow_service
node_device -->|"sends device data"| node_espnow_service
node_pairing -->|"dispatches received data"| node_device
node_sensor_manager -->|"reads sensors"| node_onewire
node_sensor_manager -->|"sets thermostat output"| node_control_logic
node_control_logic -->|"writes output"| node_i2c_expander
node_control_logic -->|"writes GPIO"| node_device_gpio
node_sensor_manager -->|"uses setpoints and status"| node_device_state
node_persistence -->|"reads and writes"| node_eeprom
node_pairing -->|"saves channel"| node_persistence
node_device -->|"updates simulation"| node_persistence

click node_device "https://github.com/servayejc/esp8266_espnow/blob/master/src/main.cpp"
click node_device_state "https://github.com/servayejc/esp8266_espnow/blob/master/src/global.h"
click node_pairing "https://github.com/servayejc/esp8266_espnow/blob/master/src/esp_now_pairing.cpp"
click node_sensor_manager "https://github.com/servayejc/esp8266_espnow/blob/master/src/Temperatures.cpp"
click node_control_logic "https://github.com/servayejc/esp8266_espnow/blob/master/src/Control.cpp"
click node_persistence "https://github.com/servayejc/esp8266_espnow/blob/master/src/Utils.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_device toneBlue
class node_pairing toneAmber
class node_sensor_manager,node_server toneMint
class node_device_state,node_control_logic,node_persistence,node_eeprom toneRose
class node_espnow_service,node_onewire,node_i2c_expander,node_device_gpio toneIndigo
```

## Components

### Firmware runtime

- [ESP8266 node](https://github.com/servayejc/esp8266_espnow/blob/master/src/main.cpp): `src/main.cpp`

### Wireless pairing

- [ESP-NOW pairing](https://github.com/servayejc/esp8266_espnow/blob/master/src/esp_now_pairing.cpp): `src/esp_now_pairing.cpp`

### Temperature sensing

- [Sensor discovery and readings](https://github.com/servayejc/esp8266_espnow/blob/master/src/Temperatures.cpp): `src/Temperatures.cpp`

### Control and state

- [Device state and messages](https://github.com/servayejc/esp8266_espnow/blob/master/src/global.h): `src/global.h`
- [Thermostat output control](https://github.com/servayejc/esp8266_espnow/blob/master/src/Control.cpp): `src/Control.cpp`
- [Settings persistence](https://github.com/servayejc/esp8266_espnow/blob/master/src/Utils.cpp): `src/Utils.cpp`
- **EEPROM**

### Other components

- **Pairing server**
- **ESP-NOW service**
- **1-Wire sensors**
- **I2C output expander**
- **ESP8266 GPIO**

## Connections

- ESP8266 node → Settings persistence: restores settings (evidence: `src/main.cpp`)
- ESP8266 node → ESP-NOW pairing: initializes radio (evidence: `src/main.cpp`)
- ESP8266 node → Sensor discovery and readings: discovers sensors (evidence: `src/main.cpp`)
- ESP8266 node → ESP-NOW pairing: checks pairing (evidence: `src/main.cpp`)
- ESP8266 node → Sensor discovery and readings: requests readings (evidence: `src/main.cpp`)
- ESP8266 node → Device state and messages: uses message state (evidence: `src/main.cpp`)
- ESP-NOW pairing → Pairing server: requests pairing (evidence: `src/esp_now_pairing.cpp`)
- Pairing server → ESP-NOW pairing: provides pairing data (evidence: `src/esp_now_pairing.cpp`)
- ESP-NOW pairing → ESP-NOW service: registers callbacks (evidence: `src/esp_now_pairing.cpp`)
- ESP8266 node → ESP-NOW service: sends device data (evidence: `src/main.cpp`)
- ESP-NOW pairing → ESP8266 node: dispatches received data (evidence: `src/esp_now_pairing.cpp`)
- Sensor discovery and readings → 1-Wire sensors: reads sensors (evidence: `src/Temperatures.cpp`)
- Sensor discovery and readings → Thermostat output control: sets thermostat output (evidence: `src/Temperatures.cpp`)
- Thermostat output control → I2C output expander: writes output (evidence: `src/Control.cpp`)
- Thermostat output control → ESP8266 GPIO: writes GPIO (evidence: `src/Control.cpp`)
- Sensor discovery and readings → Device state and messages: uses setpoints and status (evidence: `src/Temperatures.cpp`)
- Settings persistence → EEPROM: reads and writes (evidence: `src/Utils.cpp`)
- ESP-NOW pairing → Settings persistence: saves channel (evidence: `src/esp_now_pairing.cpp`)
- ESP8266 node → Settings persistence: updates simulation (evidence: `src/main.cpp`)
