# michelouieacompanado-prog/internet-of-things-with-esp32 architecture

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

- Interactive diagram: https://gitdiagram.com/michelouieacompanado-prog/internet-of-things-with-esp32
- Repository: https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32

## Overview

This repository implements a three-node ESP32 BLE Mesh smart-home system. A browser command reaches the gateway over Wi-Fi and is sent through BLE Mesh to the relay switch; independently, a light sensor reads ambient light and publishes state changes for mesh nodes. The graph includes the documented provisioning/attention support and the shared sensor and I2C layers. Relationships not visible in sampled source are attributed to the README; unsampled module internals are not inferred.

Main entry points: [`ch9/gateway/src/main.c`](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/gateway/src/main.c) (Gateway Startup), [`ch9/light_sensor/src/main.c`](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/light_sensor/src/main.c) (Sensor Startup), [`ch9/switch/src/main.c`](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/switch/src/main.c) (Switch Startup), [`ch9/gateway/src/app_web.c`](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/gateway/src/app_web.c) (HTTP Web UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Gateway"]
  node_gateway_app["Gateway Startup<br/>[main.c]"]
  node_web_ui["HTTP Web UI<br/>[app_web.c]"]
  node_wifi["Wi-Fi Connection<br/>[app_ip.c]"]
  node_gateway_ble["Mesh OnOff Client<br/>[app_ble.c]"]
end

subgraph group_sensor["Light Sensor"]
  node_light_start["Sensor Startup<br/>[main.c]"]
  node_light_reader["Light Sampling<br/>[app_sensor.c]"]
  node_sensor_ble["Mesh Status Publisher<br/>[app_ble.c]"]
end

subgraph group_switch["Relay Switch"]
  node_switch_start["Switch Startup<br/>[main.c]"]
  node_switch_ble["Mesh OnOff Models<br/>[app_ble.c]"]
  node_relay_control["Relay Control<br/>[app_sw.c]"]
end

subgraph group_shared["Shared Components"]
  node_ble_common["BLE Provisioning<br/>[app_blecommon.c]"]
  node_attention_led["Attention LED<br/>[app_ledattn.c]"]
  node_sensor_driver["TSL2561 Driver<br/>[tsl2561.c]"]
  node_i2c_driver["I2C Bus Driver<br/>[i2cdev.c]"]
end

node_browser(("Browser Client"))
node_mesh{{"BLE Mesh Network"}}
node_relay(("Relay Module"))
node_ambient(("Ambient Light"))

node_browser -->|"sends HTTP commands"| node_web_ui
node_gateway_app -->|"initializes with callback"| node_web_ui
node_gateway_app -->|"connects Wi-Fi"| node_wifi
node_wifi -->|"calls connected handler"| node_gateway_app
node_gateway_app -->|"starts server on connect"| node_web_ui
node_web_ui -->|"submits switch command"| node_gateway_ble
node_gateway_ble -->|"sends OnOff Set"| node_mesh
node_light_start -->|"starts sampling"| node_light_reader
node_light_start -->|"passes state callback"| node_sensor_ble
node_ambient -->|"provides light level"| node_light_reader
node_light_reader -->|"reads illuminance"| node_sensor_driver
node_sensor_driver -->|"uses I2C bus"| node_i2c_driver
node_sensor_ble -->|"publishes status"| node_mesh
node_switch_start -->|"initializes mesh callbacks"| node_switch_ble
node_switch_start -->|"initializes relay"| node_relay_control
node_mesh -->|"delivers OnOff commands"| node_switch_ble
node_mesh -->|"distributes status"| node_sensor_ble
node_switch_ble -->|"sets and reads state"| node_relay_control
node_relay_control -->|"drives GPIO relay"| node_relay
node_gateway_app -.->|"uses BLE support"| node_ble_common
node_light_start -.->|"uses BLE support"| node_ble_common
node_switch_start -.->|"uses BLE support"| node_ble_common
node_gateway_app -->|"initializes attention LED"| node_attention_led
node_light_start -->|"initializes attention LED"| node_attention_led
node_switch_start -->|"initializes attention LED"| node_attention_led

click node_gateway_app "https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/gateway/src/main.c"
click node_web_ui "https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/gateway/src/app_web.c"
click node_wifi "https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/gateway/src/app_ip.c"
click node_gateway_ble "https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/gateway/src/app_ble.c"
click node_light_start "https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/light_sensor/src/main.c"
click node_light_reader "https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/light_sensor/src/app_sensor.c"
click node_sensor_ble "https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/light_sensor/src/app_ble.c"
click node_switch_start "https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/switch/src/main.c"
click node_switch_ble "https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/switch/src/app_ble.c"
click node_relay_control "https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/switch/src/app_sw.c"
click node_ble_common "https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/common/ble/app_blecommon.c"
click node_attention_led "https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/common/led/app_ledattn.c"
click node_sensor_driver "https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/common/esp-idf-lib/components/tsl2561/tsl2561.c"
click node_i2c_driver "https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/common/esp-idf-lib/components/i2cdev/i2cdev.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_gateway_app,node_web_ui,node_wifi,node_gateway_ble,node_browser toneBlue
class node_light_start,node_light_reader,node_sensor_ble toneAmber
class node_switch_start,node_switch_ble,node_relay_control toneMint
class node_ble_common,node_attention_led,node_sensor_driver,node_i2c_driver toneRose
class node_mesh,node_relay,node_ambient toneIndigo
```

## Components

### Gateway

- [Gateway Startup](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/gateway/src/main.c): `ch9/gateway/src/main.c`
- [HTTP Web UI](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/gateway/src/app_web.c): `ch9/gateway/src/app_web.c`
- [Wi-Fi Connection](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/gateway/src/app_ip.c): `ch9/gateway/src/app_ip.c`
- [Mesh OnOff Client](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/gateway/src/app_ble.c): `ch9/gateway/src/app_ble.c`

### Light Sensor

- [Sensor Startup](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/light_sensor/src/main.c): `ch9/light_sensor/src/main.c`
- [Light Sampling](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/light_sensor/src/app_sensor.c): `ch9/light_sensor/src/app_sensor.c`
- [Mesh Status Publisher](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/light_sensor/src/app_ble.c): `ch9/light_sensor/src/app_ble.c`

### Relay Switch

- [Switch Startup](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/switch/src/main.c): `ch9/switch/src/main.c`
- [Mesh OnOff Models](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/switch/src/app_ble.c): `ch9/switch/src/app_ble.c`
- [Relay Control](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/ch9/switch/src/app_sw.c): `ch9/switch/src/app_sw.c`

### Shared Components

- [BLE Provisioning](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/common/ble/app_blecommon.c): `common/ble/app_blecommon.c`
- [Attention LED](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/common/led/app_ledattn.c): `common/led/app_ledattn.c`
- [TSL2561 Driver](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/common/esp-idf-lib/components/tsl2561/tsl2561.c): `common/esp-idf-lib/components/tsl2561/tsl2561.c`
- [I2C Bus Driver](https://github.com/michelouieacompanado-prog/internet-of-things-with-esp32/blob/main/common/esp-idf-lib/components/i2cdev/i2cdev.c): `common/esp-idf-lib/components/i2cdev/i2cdev.c`

### Other components

- **Browser Client**
- **BLE Mesh Network**
- **Relay Module**
- **Ambient Light**

## Connections

- Browser Client → HTTP Web UI: sends HTTP commands (evidence: `README.md`)
- Gateway Startup → HTTP Web UI: initializes with callback (evidence: `ch9/gateway/src/main.c`)
- Gateway Startup → Wi-Fi Connection: connects Wi-Fi (evidence: `ch9/gateway/src/main.c`)
- Wi-Fi Connection → Gateway Startup: calls connected handler (evidence: `README.md`)
- Gateway Startup → HTTP Web UI: starts server on connect (evidence: `ch9/gateway/src/main.c`)
- HTTP Web UI → Mesh OnOff Client: submits switch command (evidence: `README.md`)
- Mesh OnOff Client → BLE Mesh Network: sends OnOff Set (evidence: `README.md`)
- Sensor Startup → Light Sampling: starts sampling (evidence: `ch9/light_sensor/src/main.c`)
- Sensor Startup → Mesh Status Publisher: passes state callback (evidence: `ch9/light_sensor/src/main.c`)
- Ambient Light → Light Sampling: provides light level (evidence: `README.md`)
- Light Sampling → TSL2561 Driver: reads illuminance (evidence: `README.md`)
- TSL2561 Driver → I2C Bus Driver: uses I2C bus
- Mesh Status Publisher → BLE Mesh Network: publishes status (evidence: `README.md`)
- Switch Startup → Mesh OnOff Models: initializes mesh callbacks (evidence: `ch9/switch/src/main.c`)
- Switch Startup → Relay Control: initializes relay (evidence: `ch9/switch/src/main.c`)
- BLE Mesh Network → Mesh OnOff Models: delivers OnOff commands (evidence: `README.md`)
- BLE Mesh Network → Mesh Status Publisher: distributes status (evidence: `README.md`)
- Mesh OnOff Models → Relay Control: sets and reads state
- Relay Control → Relay Module: drives GPIO relay (evidence: `README.md`)
- Gateway Startup → BLE Provisioning: uses BLE support
- Sensor Startup → BLE Provisioning: uses BLE support
- Switch Startup → BLE Provisioning: uses BLE support
- Gateway Startup → Attention LED: initializes attention LED (evidence: `ch9/gateway/src/main.c`)
- Sensor Startup → Attention LED: initializes attention LED (evidence: `ch9/light_sensor/src/main.c`)
- Switch Startup → Attention LED: initializes attention LED (evidence: `ch9/switch/src/main.c`)
