# yangyuanxin/iotsensordetect architecture

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

- Interactive diagram: https://gitdiagram.com/yangyuanxin/iotsensordetect
- Repository: https://github.com/yangyuanxin/iotsensordetect
- Video tour (about a minute): https://gitdiagram.com/yangyuanxin/iotsensordetect/video

## Overview

IotSensorDetect is STM32 firmware for gas sensing, organized around an MVC application and a state-driven detection workflow. The documented control mode accepts START, STOP, and return/previous commands; detection moves through calibration, detection, and result states. A separate auto-report mode sends periodic device status and sensor values to the app. The graph includes the sensor/display, protocol, and MQTT layers supported by the tree and documentation; most application implementation files were not sampled, so uncertain internal call wiring is omitted.

Main entry points: [`Software/APP/Controller.c`](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/APP/Controller.c) (Controller), [`Software/Common/mqttclient/mqttclient/mqttclient.c`](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/Common/mqttclient/mqttclient/mqttclient.c) (MQTT client), [`Software/Bsp/MQ_2.c`](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/Bsp/MQ_2.c) (Gas sensor), [`Software/APP/App.c`](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/APP/App.c) (App coordinator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_application["Application"]
  node_app["App coordinator<br/>[App.c]"]
  node_controller["Controller<br/>[Controller.c]"]
  node_model["State model<br/>[Model.c]"]
end

subgraph group_sensing["Sensing and UI"]
  node_view["Display view<br/>[View.c]"]
  node_gas_sensor["Gas sensor<br/>[MQ_2.c]"]
  node_sensor_aux["Sensor interface<br/>[Bh750.c]"]
  node_lcd["LCD driver<br/>[Lcd.c]"]
end

subgraph group_connectivity["Connectivity"]
  node_protocol["Sensor protocol<br/>[sensor_protocol.c]"]
  node_json["JSON codec<br/>[cJSON.c]"]
  node_mqtt_api["MQTT client<br/>[mqttclient.c]"]
  node_mqtt_packet["MQTT packet"]
  node_network["Network transport<br/>[network.c]"]
end

subgraph group_platform["MCU platform"]
  node_entry["Firmware entry<br/>[main.c]"]
  node_peripherals["MCU peripherals<br/>[adc.c]"]
end

node_user(("App user"))
node_mobile_app(("Mobile app"))
node_broker(("MQTT broker"))

node_user -->|"issues commands"| node_mobile_app
node_mobile_app -->|"sends control"| node_controller
node_entry -->|"starts"| node_app
node_app -->|"coordinates"| node_controller
node_controller -->|"dispatches events"| node_model
node_model -->|"returns state"| node_controller
node_controller -->|"requests readings"| node_gas_sensor
node_gas_sensor -->|"returns values"| node_controller
node_controller -->|"uses sensor interface"| node_sensor_aux
node_controller -->|"updates display"| node_view
node_view -->|"renders"| node_lcd
node_controller -->|"encodes reports"| node_protocol
node_controller -->|"parses messages"| node_json
node_controller -->|"publishes and subscribes"| node_mqtt_api
node_mqtt_api -->|"serializes packets"| node_mqtt_packet
node_mqtt_api -->|"transfers packets"| node_network
node_network -->|"connects"| node_broker
node_broker -->|"delivers messages"| node_mqtt_api
node_peripherals -->|"supports acquisition"| node_gas_sensor

click node_entry "https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/McuPlatform/Core/Src/main.c"
click node_app "https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/APP/App.c"
click node_controller "https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/APP/Controller.c"
click node_model "https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/APP/Model.c"
click node_view "https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/APP/View.c"
click node_gas_sensor "https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/Bsp/MQ_2.c"
click node_sensor_aux "https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/Bsp/Bh750.c"
click node_lcd "https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/Bsp/Lcd.c"
click node_protocol "https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/Common/data_protocol/sensor_protocol.c"
click node_json "https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/Common/cJSON/cJSON.c"
click node_mqtt_api "https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/Common/mqttclient/mqttclient/mqttclient.c"
click node_mqtt_packet "https://github.com/yangyuanxin/iotsensordetect/tree/main/Software/Common/mqttclient/mqtt"
click node_network "https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/Common/mqttclient/network/network.c"
click node_peripherals "https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/McuPlatform/Core/Src/adc.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_app,node_controller,node_model,node_user toneBlue
class node_view,node_gas_sensor,node_sensor_aux,node_lcd toneAmber
class node_protocol,node_json,node_mqtt_api,node_mqtt_packet,node_network toneMint
class node_entry,node_peripherals toneRose
class node_mobile_app,node_broker toneIndigo
```

## Components

### Application

- [App coordinator](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/APP/App.c): `Software/APP/App.c`
- [Controller](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/APP/Controller.c): `Software/APP/Controller.c`
- [State model](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/APP/Model.c): `Software/APP/Model.c`

### Sensing and UI

- [Display view](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/APP/View.c): `Software/APP/View.c`
- [Gas sensor](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/Bsp/MQ_2.c): `Software/Bsp/MQ_2.c`
- [Sensor interface](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/Bsp/Bh750.c): `Software/Bsp/Bh750.c`
- [LCD driver](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/Bsp/Lcd.c): `Software/Bsp/Lcd.c`

### Connectivity

- [Sensor protocol](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/Common/data_protocol/sensor_protocol.c): `Software/Common/data_protocol/sensor_protocol.c`
- [JSON codec](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/Common/cJSON/cJSON.c): `Software/Common/cJSON/cJSON.c`
- [MQTT client](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/Common/mqttclient/mqttclient/mqttclient.c): `Software/Common/mqttclient/mqttclient/mqttclient.c`
- [MQTT packet](https://github.com/yangyuanxin/iotsensordetect/tree/main/Software/Common/mqttclient/mqtt): `Software/Common/mqttclient/mqtt`
- [Network transport](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/Common/mqttclient/network/network.c): `Software/Common/mqttclient/network/network.c`

### MCU platform

- [Firmware entry](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/McuPlatform/Core/Src/main.c): `Software/McuPlatform/Core/Src/main.c`
- [MCU peripherals](https://github.com/yangyuanxin/iotsensordetect/blob/main/Software/McuPlatform/Core/Src/adc.c): `Software/McuPlatform/Core/Src/adc.c`

### Other components

- **App user**
- **Mobile app**
- **MQTT broker**

## Connections

- App user → Mobile app: issues commands
- Mobile app → Controller: sends control
- Firmware entry → App coordinator: starts
- App coordinator → Controller: coordinates
- Controller → State model: dispatches events
- State model → Controller: returns state
- Controller → Gas sensor: requests readings
- Gas sensor → Controller: returns values
- Controller → Sensor interface: uses sensor interface
- Controller → Display view: updates display
- Display view → LCD driver: renders
- Controller → Sensor protocol: encodes reports
- Controller → JSON codec: parses messages
- Controller → MQTT client: publishes and subscribes
- MQTT client → MQTT packet: serializes packets
- MQTT client → Network transport: transfers packets
- Network transport → MQTT broker: connects
- MQTT broker → MQTT client: delivers messages
- MCU peripherals → Gas sensor: supports acquisition
