# leo4bits/person_fire_smoke_detection_esp32 architecture

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

- Interactive diagram: https://gitdiagram.com/leo4bits/person_fire_smoke_detection_esp32
- Repository: https://github.com/leo4bits/person_fire_smoke_detection_esp32

## Overview

This repository implements a fire-and-smoke monitoring prototype: ESP32 temperature, humidity, and gas readings are classified while webcam frames are analyzed for people, fire, and smoke, with both results shown in a live overlay. A separate collector path saves raw sensor readings as JSON. The graph follows explicit calls and data transfers in the sampled runtime files; SAHI is documented in code as an alternative detector, while README capabilities without clear runtime wiring are not expanded.

Main entry points: [`mainTest.py`](https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/mainTest.py) (Live monitor), [`GetDataFromSensor/GetDataSensor/src/main.cpp`](https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/GetDataFromSensor/GetDataSensor/src/main.cpp) (ESP32 sampling), [`MODEL_USING.py`](https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/MODEL_USING.py) (Detection facade), [`GetDataFromSensor/GetDataSensor/src/sensors.cpp`](https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/GetDataFromSensor/GetDataSensor/src/sensors.cpp) (Sensor drivers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firmware["Sensor firmware"]
  node_firmware_loop["ESP32 sampling<br/>[main.cpp]"]
  node_sensor_driver["Sensor drivers<br/>[sensors.cpp]"]
end

subgraph group_sensor["Sensor processing"]
  node_serial_reader["UART reader<br/>[thread.py]"]
  node_numeric_processing["Gas classification"]
  node_rf_model["Air quality model"]
  node_raw_collector["Raw data collector<br/>[pushData.py]"]
  node_alternate_collector["Sensor data saver"]
  node_json_output["Saved sensor JSON"]
end

subgraph group_vision["Vision detection"]
  node_image_preprocessing["CLAHE enhancement"]
  node_detector["Detection facade<br/>[MODEL_USING.py]"]
  node_yolo_weights["YOLO weights<br/>[best.pt]"]
end

subgraph group_app["Live application"]
  node_app_entry["Live monitor<br/>[mainTest.py]"]
  node_overlay_text["Overlay labels<br/>[outputGUI.py]"]
end

node_operator(("Operator"))
node_sensors(("DHT11 / MQ135"))
node_webcam(("Webcam"))
node_display(("Live display"))
node_yolo_runtime["Ultralytics YOLO"]
node_sahi_runtime["SAHI inference"]

node_sensors -->|"provides readings"| node_sensor_driver
node_firmware_loop -->|"reads sensors"| node_sensor_driver
node_sensor_driver -->|"returns measurements"| node_firmware_loop
node_firmware_loop -->|"streams JSON over UART"| node_serial_reader
node_firmware_loop -->|"streams JSON over UART"| node_raw_collector
node_firmware_loop -->|"streams JSON over UART"| node_alternate_collector
node_serial_reader -->|"classifies readings"| node_numeric_processing
node_numeric_processing -->|"loads model"| node_rf_model
node_raw_collector -->|"writes on interrupt"| node_json_output
node_alternate_collector -->|"writes on interrupt"| node_json_output
node_webcam -->|"provides frames"| node_app_entry
node_app_entry -->|"enhances frames"| node_image_preprocessing
node_app_entry -->|"requests detections"| node_detector
node_detector -->|"runs YOLO"| node_yolo_runtime
node_detector -.->|"runs sliced inference"| node_sahi_runtime
node_yolo_weights -->|"loads weights"| node_detector
node_app_entry -->|"reads predicted state"| node_serial_reader
node_app_entry -->|"formats labels"| node_overlay_text
node_app_entry -->|"renders overlay"| node_display
node_operator -->|"views results"| node_display

click node_firmware_loop "https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/GetDataFromSensor/GetDataSensor/src/main.cpp"
click node_sensor_driver "https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/GetDataFromSensor/GetDataSensor/src/sensors.cpp"
click node_serial_reader "https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/GetDataFromSensor/threadGetData/thread.py"
click node_numeric_processing "https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/PreProcessing/numPreProcessing.py"
click node_rf_model "https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/random_forest_air_quality.pkl"
click node_raw_collector "https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/GetDataFromSensor/PushDataForModel/pushData.py"
click node_alternate_collector "https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/GetDataFromSensor/SaveDataFormSensors/saveDataFromsens.py"
click node_app_entry "https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/mainTest.py"
click node_image_preprocessing "https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/PreProcessing/imgPreProcessing.py"
click node_detector "https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/MODEL_USING.py"
click node_yolo_weights "https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/best.pt"
click node_overlay_text "https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/PreProcessing/outputGUI.py"

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_loop,node_sensor_driver toneBlue
class node_serial_reader,node_numeric_processing,node_rf_model,node_raw_collector,node_alternate_collector,node_json_output toneAmber
class node_image_preprocessing,node_detector,node_yolo_weights toneMint
class node_app_entry,node_overlay_text toneRose
class node_operator,node_sensors,node_webcam,node_display,node_yolo_runtime,node_sahi_runtime toneIndigo
```

## Components

### Sensor firmware

- [ESP32 sampling](https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/GetDataFromSensor/GetDataSensor/src/main.cpp): `GetDataFromSensor/GetDataSensor/src/main.cpp`
- [Sensor drivers](https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/GetDataFromSensor/GetDataSensor/src/sensors.cpp): `GetDataFromSensor/GetDataSensor/src/sensors.cpp`

### Sensor processing

- [UART reader](https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/GetDataFromSensor/threadGetData/thread.py): `GetDataFromSensor/threadGetData/thread.py`
- [Gas classification](https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/PreProcessing/numPreProcessing.py): `PreProcessing/numPreProcessing.py`
- [Air quality model](https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/random_forest_air_quality.pkl): `random_forest_air_quality.pkl`
- [Raw data collector](https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/GetDataFromSensor/PushDataForModel/pushData.py): `GetDataFromSensor/PushDataForModel/pushData.py`
- [Sensor data saver](https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/GetDataFromSensor/SaveDataFormSensors/saveDataFromsens.py): `GetDataFromSensor/SaveDataFormSensors/saveDataFromsens.py`
- **Saved sensor JSON**

### Vision detection

- [CLAHE enhancement](https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/PreProcessing/imgPreProcessing.py): `PreProcessing/imgPreProcessing.py`
- [Detection facade](https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/MODEL_USING.py): `MODEL_USING.py`
- [YOLO weights](https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/best.pt): `best.pt`

### Live application

- [Live monitor](https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/mainTest.py): `mainTest.py`
- [Overlay labels](https://github.com/leo4bits/person_fire_smoke_detection_esp32/blob/main/PreProcessing/outputGUI.py): `PreProcessing/outputGUI.py`

### Other components

- **Operator**
- **DHT11 / MQ135**
- **Webcam**
- **Live display**
- **Ultralytics YOLO**
- **SAHI inference**

## Connections

- DHT11 / MQ135 → Sensor drivers: provides readings
- ESP32 sampling → Sensor drivers: reads sensors
- Sensor drivers → ESP32 sampling: returns measurements
- ESP32 sampling → UART reader: streams JSON over UART
- ESP32 sampling → Raw data collector: streams JSON over UART
- ESP32 sampling → Sensor data saver: streams JSON over UART
- UART reader → Gas classification: classifies readings
- Gas classification → Air quality model: loads model
- Raw data collector → Saved sensor JSON: writes on interrupt
- Sensor data saver → Saved sensor JSON: writes on interrupt
- Webcam → Live monitor: provides frames
- Live monitor → CLAHE enhancement: enhances frames
- Live monitor → Detection facade: requests detections
- Detection facade → Ultralytics YOLO: runs YOLO
- Detection facade → SAHI inference: runs sliced inference
- YOLO weights → Detection facade: loads weights
- Live monitor → UART reader: reads predicted state
- Live monitor → Overlay labels: formats labels
- Live monitor → Live display: renders overlay
- Operator → Live display: views results
