# yv798an/tiny_rtgw_rv307 architecture

> Architecture diagram of the GitHub repository yv798an/tiny_rtgw_rv307, 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/yv798an/tiny_rtgw_rv307
- Repository: https://github.com/yv798an/tiny_rtgw_rv307

## Overview

Tiny_RTGW_RV307 is an IoT gateway: edge firmware samples temperature, humidity, and light, displays readings locally, and exchanges data and LED commands over UART with an ESP32-C6 MQTT bridge; a Flask web service provides live monitoring, history, and remote control. The README documents the bridge and end-to-end protocol, but its firmware is absent from the supplied tree. The sampled firmware entry point and sensor service support the edge flow; unsampled subsystem wiring is included only where documented.

Main entry points: [`iot_web/app.py`](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/iot_web/app.py) (Flask and SocketIO), [`Internet_Edge/equipment/sensor/sensor_service.c`](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/equipment/sensor/sensor_service.c) (Sensor Service), [`Internet_Edge/equipment/usart/uart2.c`](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/equipment/usart/uart2.c) (UART2 Service), [`Internet_Edge/User/main.c`](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/User/main.c) (RT-Thread Main)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_edge["Edge Firmware"]
  node_main["RT-Thread Main<br/>[main.c]"]
  node_uart["UART2 Service<br/>[uart2.c]"]
  node_led["LED GPIO<br/>[drv_gpio.c]"]
end

subgraph group_sensing["Sensing and State"]
  node_sensor["Sensor Service<br/>[sensor_service.c]"]
  node_sensor_state[("Shared Sensor State<br/>[sensor_data.c]")]
  node_dht["DHT20 Driver<br/>[DHT20.c]"]
  node_adc["ADC Sampling<br/>[bsp_adc.c]"]
  node_timer["ADC Trigger<br/>[bsp_tim.c]"]
end

subgraph group_web["Web Service"]
  node_app["Flask and SocketIO<br/>[app.py]"]
  node_history[("SQLite History<br/>[app.py]")]
end

subgraph group_display["Local Display"]
  node_gui_init["GUI Initialization<br/>[GUI_init.c]"]
  node_dashboard["LCD Dashboard<br/>[GUI_dashboard.c]"]
  node_lcd["ILI9341 Display<br/>[ili9341.c]"]
end

node_user(("Browser User"))
node_bridge["ESP32-C6 Bridge"]
node_mqtt["MQTT Broker"]
node_browser(("Web Dashboard"))

node_main -->|"starts thread"| node_sensor
node_main -->|"starts thread"| node_uart
node_main -->|"initializes"| node_gui_init
node_sensor -->|"reads"| node_dht
node_sensor -->|"samples"| node_adc
node_sensor -->|"initializes"| node_timer
node_sensor -->|"updates state"| node_sensor_state
node_uart -->|"reads state"| node_sensor_state
node_uart -->|"controls"| node_led
node_gui_init -->|"initializes"| node_dashboard
node_dashboard -->|"renders"| node_lcd
node_uart -->|"UART frames"| node_bridge
node_bridge -->|"UART commands"| node_uart
node_bridge -->|"publishes data"| node_mqtt
node_mqtt -->|"delivers commands"| node_bridge
node_mqtt -->|"delivers telemetry"| node_app
node_app -->|"publishes control"| node_mqtt
node_app -->|"writes readings"| node_history
node_app -->|"queries history"| node_history
node_app -->|"pushes live data"| node_browser
node_browser -->|"requests history"| node_app
node_browser -->|"sends LED control"| node_app

click node_main "https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/User/main.c"
click node_sensor "https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/equipment/sensor/sensor_service.c"
click node_sensor_state "https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/equipment/sensor/sensor_data.c"
click node_dht "https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/equipment/DHT20/DHT20.c"
click node_adc "https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/equipment/ADC/bsp_adc.c"
click node_timer "https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/equipment/TIM/bsp_tim.c"
click node_uart "https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/equipment/usart/uart2.c"
click node_led "https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/drivers/drv_gpio.c"
click node_gui_init "https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/GUI/GUI_init.c"
click node_dashboard "https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/GUI/GUI_dashboard.c"
click node_lcd "https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/GUI/ili9341.c"
click node_app "https://github.com/yv798an/tiny_rtgw_rv307/blob/main/iot_web/app.py"
click node_history "https://github.com/yv798an/tiny_rtgw_rv307/blob/main/iot_web/app.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_main,node_uart,node_led,node_user toneBlue
class node_sensor,node_sensor_state,node_dht,node_adc,node_timer toneAmber
class node_app,node_history toneMint
class node_gui_init,node_dashboard,node_lcd toneRose
class node_bridge,node_mqtt,node_browser toneIndigo
```

## Components

### Edge Firmware

- [RT-Thread Main](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/User/main.c): `Internet_Edge/User/main.c`
- [UART2 Service](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/equipment/usart/uart2.c): `Internet_Edge/equipment/usart/uart2.c`
- [LED GPIO](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/drivers/drv_gpio.c): `Internet_Edge/drivers/drv_gpio.c`

### Sensing and State

- [Sensor Service](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/equipment/sensor/sensor_service.c): `Internet_Edge/equipment/sensor/sensor_service.c`
- [Shared Sensor State](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/equipment/sensor/sensor_data.c): `Internet_Edge/equipment/sensor/sensor_data.c`
- [DHT20 Driver](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/equipment/DHT20/DHT20.c): `Internet_Edge/equipment/DHT20/DHT20.c`
- [ADC Sampling](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/equipment/ADC/bsp_adc.c): `Internet_Edge/equipment/ADC/bsp_adc.c`
- [ADC Trigger](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/equipment/TIM/bsp_tim.c): `Internet_Edge/equipment/TIM/bsp_tim.c`

### Web Service

- [Flask and SocketIO](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/iot_web/app.py): `iot_web/app.py`
- [SQLite History](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/iot_web/app.py): `iot_web/app.py`

### Local Display

- [GUI Initialization](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/GUI/GUI_init.c): `Internet_Edge/GUI/GUI_init.c`
- [LCD Dashboard](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/GUI/GUI_dashboard.c): `Internet_Edge/GUI/GUI_dashboard.c`
- [ILI9341 Display](https://github.com/yv798an/tiny_rtgw_rv307/blob/main/Internet_Edge/GUI/ili9341.c): `Internet_Edge/GUI/ili9341.c`

### Other components

- **Browser User**
- **ESP32-C6 Bridge**
- **MQTT Broker**
- **Web Dashboard**

## Connections

- RT-Thread Main → Sensor Service: starts thread
- RT-Thread Main → UART2 Service: starts thread
- RT-Thread Main → GUI Initialization: initializes
- Sensor Service → DHT20 Driver: reads
- Sensor Service → ADC Sampling: samples
- Sensor Service → ADC Trigger: initializes
- Sensor Service → Shared Sensor State: updates state
- UART2 Service → Shared Sensor State: reads state
- UART2 Service → LED GPIO: controls
- GUI Initialization → LCD Dashboard: initializes
- LCD Dashboard → ILI9341 Display: renders
- UART2 Service → ESP32-C6 Bridge: UART frames
- ESP32-C6 Bridge → UART2 Service: UART commands
- ESP32-C6 Bridge → MQTT Broker: publishes data
- MQTT Broker → ESP32-C6 Bridge: delivers commands
- MQTT Broker → Flask and SocketIO: delivers telemetry
- Flask and SocketIO → MQTT Broker: publishes control
- Flask and SocketIO → SQLite History: writes readings
- Flask and SocketIO → SQLite History: queries history
- Flask and SocketIO → Web Dashboard: pushes live data
- Web Dashboard → Flask and SocketIO: requests history
- Web Dashboard → Flask and SocketIO: sends LED control
