# peterlourens/osventilationidf architecture

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

- Interactive diagram: https://gitdiagram.com/peterlourens/osventilationidf
- Repository: https://github.com/peterlourens/osventilationidf

## Overview

OSVentilation is ESP32-S3 firmware for demand-controlled ventilation, replacing an Itho controller. A user sets fan speed through the HTTP API or MQTT; the controller also reads configured I2C sensors and uses state-machine logic to govern ventilation and valve movement. Other documented capabilities include a web UI with WebSocket updates, LCD/RTC support, Wi-Fi and Ethernet networking, and periodic InfluxDB reporting. The README and source index support these major subsystems, but most implementation files were not excerpted, so uncertain internal call links are omitted.

Main entry points: [`main/statemachine.c`](https://github.com/peterlourens/osventilationidf/blob/main/main/statemachine.c) (Ventilation state machine), [`main/http_functions.c`](https://github.com/peterlourens/osventilationidf/blob/main/main/http_functions.c) (HTTP API), [`main/network_manager.c`](https://github.com/peterlourens/osventilationidf/blob/main/main/network_manager.c) (Network manager), [`main/i2c_sensors.c`](https://github.com/peterlourens/osventilationidf/blob/main/main/i2c_sensors.c) (I2C sensor access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Ventilation control"]
  node_statemachine["Ventilation state machine<br/>[statemachine.c]"]
  node_fancontrol["Fan control<br/>[fancontrol.c]"]
  node_valvecontrol["Valve control<br/>[valvecontrol.c]"]
end

subgraph group_sensing["Sensors and actuators"]
  node_sensor_task["Sensor polling task<br/>[task_i2c_sensors.c]"]
  node_i2c_sensors["I2C sensor access<br/>[i2c_sensors.c]"]
  node_bme680["BME68x driver<br/>[bme68x.c]"]
  node_bsec["BSEC integration<br/>[bsec_integration.c]"]
  node_rtc_task["RTC task<br/>[task_i2c_ds3231.c]"]
end

subgraph group_interfaces["User and telemetry interfaces"]
  node_http_api["HTTP API<br/>[http_functions.c]"]
  node_mqtt["MQTT interface<br/>[mqtt.c]"]
  node_web_ui["Web UI<br/>[ui.js]"]
  node_ws_updates["WebSocket updates"]
  node_influx_task["InfluxDB reporting task<br/>[task_influxdb.c]"]
  node_influx["InfluxDB client<br/>[influxdb.c]"]
  node_lcd_task["LCD task<br/>[task_i2c_lcd.c]"]
end

subgraph group_platform["Runtime and connectivity"]
  node_network_manager["Network manager<br/>[network_manager.c]"]
  node_ethernet["Ethernet interface<br/>[eth_functions.c]"]
  node_wifi["Wi-Fi interface<br/>[wifi_functions.c]"]
  node_config["Configuration and files<br/>[config_files.c]"]
  node_sys_stats["System statistics<br/>[sys_stats.c]"]
  node_syslog["Syslog<br/>[syslog.c]"]
  node_pushbutton["Pushbuttons<br/>[task_pushbutton.c]"]
end

node_operator(("Operator"))

node_operator -->|"sets speed"| node_http_api
node_operator -->|"sets speed"| node_mqtt
node_web_ui -.->|"uses API"| node_http_api
node_http_api -.->|"applies control"| node_statemachine
node_mqtt -.->|"applies control"| node_statemachine
node_statemachine -.->|"sets fan speed"| node_fancontrol
node_statemachine -.->|"controls valves"| node_valvecontrol
node_sensor_task -->|"reads sensors"| node_i2c_sensors
node_i2c_sensors -.->|"supports sensor"| node_bme680
node_bsec -->|"integrates driver"| node_bme680
node_influx_task -->|"reports periodically"| node_influx
node_http_api -.->|"serves updates"| node_ws_updates
node_network_manager -->|"manages interface"| node_ethernet
node_network_manager -.->|"manages interface"| node_wifi

click node_http_api "https://github.com/peterlourens/osventilationidf/blob/main/main/http_functions.c"
click node_mqtt "https://github.com/peterlourens/osventilationidf/blob/main/main/mqtt.c"
click node_web_ui "https://github.com/peterlourens/osventilationidf/blob/main/web/ui.js"
click node_ws_updates "https://github.com/peterlourens/osventilationidf/blob/main/main/http_send_ws_data.c"
click node_influx_task "https://github.com/peterlourens/osventilationidf/blob/main/main/task_influxdb.c"
click node_influx "https://github.com/peterlourens/osventilationidf/blob/main/main/influxdb.c"
click node_statemachine "https://github.com/peterlourens/osventilationidf/blob/main/main/statemachine.c"
click node_fancontrol "https://github.com/peterlourens/osventilationidf/blob/main/main/fancontrol.c"
click node_valvecontrol "https://github.com/peterlourens/osventilationidf/blob/main/main/valvecontrol.c"
click node_sensor_task "https://github.com/peterlourens/osventilationidf/blob/main/main/task_i2c_sensors.c"
click node_i2c_sensors "https://github.com/peterlourens/osventilationidf/blob/main/main/i2c_sensors.c"
click node_bme680 "https://github.com/peterlourens/osventilationidf/blob/main/components/bme680/src/bme68x.c"
click node_bsec "https://github.com/peterlourens/osventilationidf/blob/main/components/bsec/src/bsec_integration.c"
click node_rtc_task "https://github.com/peterlourens/osventilationidf/blob/main/main/task_i2c_ds3231.c"
click node_lcd_task "https://github.com/peterlourens/osventilationidf/blob/main/main/task_i2c_lcd.c"
click node_network_manager "https://github.com/peterlourens/osventilationidf/blob/main/main/network_manager.c"
click node_ethernet "https://github.com/peterlourens/osventilationidf/blob/main/main/eth_functions.c"
click node_wifi "https://github.com/peterlourens/osventilationidf/blob/main/main/wifi_functions.c"
click node_config "https://github.com/peterlourens/osventilationidf/blob/main/main/config_files.c"
click node_sys_stats "https://github.com/peterlourens/osventilationidf/blob/main/main/sys_stats.c"
click node_syslog "https://github.com/peterlourens/osventilationidf/blob/main/main/syslog.c"
click node_pushbutton "https://github.com/peterlourens/osventilationidf/blob/main/main/task_pushbutton.c"

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_statemachine,node_fancontrol,node_valvecontrol toneBlue
class node_sensor_task,node_i2c_sensors,node_bme680,node_bsec,node_rtc_task toneAmber
class node_http_api,node_mqtt,node_web_ui,node_ws_updates,node_influx_task,node_influx,node_lcd_task toneMint
class node_network_manager,node_ethernet,node_wifi,node_config,node_sys_stats,node_syslog,node_pushbutton toneRose
class node_operator toneIndigo
```

## Components

### Ventilation control

- [Ventilation state machine](https://github.com/peterlourens/osventilationidf/blob/main/main/statemachine.c): `main/statemachine.c`
- [Fan control](https://github.com/peterlourens/osventilationidf/blob/main/main/fancontrol.c): `main/fancontrol.c`
- [Valve control](https://github.com/peterlourens/osventilationidf/blob/main/main/valvecontrol.c): `main/valvecontrol.c`

### Sensors and actuators

- [Sensor polling task](https://github.com/peterlourens/osventilationidf/blob/main/main/task_i2c_sensors.c): `main/task_i2c_sensors.c`
- [I2C sensor access](https://github.com/peterlourens/osventilationidf/blob/main/main/i2c_sensors.c): `main/i2c_sensors.c`
- [BME68x driver](https://github.com/peterlourens/osventilationidf/blob/main/components/bme680/src/bme68x.c): `components/bme680/src/bme68x.c`
- [BSEC integration](https://github.com/peterlourens/osventilationidf/blob/main/components/bsec/src/bsec_integration.c): `components/bsec/src/bsec_integration.c`
- [RTC task](https://github.com/peterlourens/osventilationidf/blob/main/main/task_i2c_ds3231.c): `main/task_i2c_ds3231.c`

### User and telemetry interfaces

- [HTTP API](https://github.com/peterlourens/osventilationidf/blob/main/main/http_functions.c): `main/http_functions.c`
- [MQTT interface](https://github.com/peterlourens/osventilationidf/blob/main/main/mqtt.c): `main/mqtt.c`
- [Web UI](https://github.com/peterlourens/osventilationidf/blob/main/web/ui.js): `web/ui.js`
- [WebSocket updates](https://github.com/peterlourens/osventilationidf/blob/main/main/http_send_ws_data.c): `main/http_send_ws_data.c`
- [InfluxDB reporting task](https://github.com/peterlourens/osventilationidf/blob/main/main/task_influxdb.c): `main/task_influxdb.c`
- [InfluxDB client](https://github.com/peterlourens/osventilationidf/blob/main/main/influxdb.c): `main/influxdb.c`
- [LCD task](https://github.com/peterlourens/osventilationidf/blob/main/main/task_i2c_lcd.c): `main/task_i2c_lcd.c`

### Runtime and connectivity

- [Network manager](https://github.com/peterlourens/osventilationidf/blob/main/main/network_manager.c): `main/network_manager.c`
- [Ethernet interface](https://github.com/peterlourens/osventilationidf/blob/main/main/eth_functions.c): `main/eth_functions.c`
- [Wi-Fi interface](https://github.com/peterlourens/osventilationidf/blob/main/main/wifi_functions.c): `main/wifi_functions.c`
- [Configuration and files](https://github.com/peterlourens/osventilationidf/blob/main/main/config_files.c): `main/config_files.c`
- [System statistics](https://github.com/peterlourens/osventilationidf/blob/main/main/sys_stats.c): `main/sys_stats.c`
- [Syslog](https://github.com/peterlourens/osventilationidf/blob/main/main/syslog.c): `main/syslog.c`
- [Pushbuttons](https://github.com/peterlourens/osventilationidf/blob/main/main/task_pushbutton.c): `main/task_pushbutton.c`

### Other components

- **Operator**

## Connections

- Operator → HTTP API: sets speed
- Operator → MQTT interface: sets speed
- Web UI → HTTP API: uses API
- HTTP API → Ventilation state machine: applies control
- MQTT interface → Ventilation state machine: applies control
- Ventilation state machine → Fan control: sets fan speed
- Ventilation state machine → Valve control: controls valves
- Sensor polling task → I2C sensor access: reads sensors
- I2C sensor access → BME68x driver: supports sensor
- BSEC integration → BME68x driver: integrates driver
- InfluxDB reporting task → InfluxDB client: reports periodically
- HTTP API → WebSocket updates: serves updates
- Network manager → Ethernet interface: manages interface
- Network manager → Wi-Fi interface: manages interface
