# aclab-hcmut/thesis_mdt263_weather_monitor architecture

> Architecture diagram of the GitHub repository aclab-hcmut/thesis_mdt263_weather_monitor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aclab-hcmut/thesis_mdt263_weather_monitor
- Repository: https://github.com/aclab-hcmut/thesis_mdt263_weather_monitor

## Overview

##### Project Type and Purpose
- This project is an embedded firmware project for an IoT device (likely ESP32/ESP8266). It is designed to interface with various sensors (including an ultrasonic sensor and potentially a GPS) and communicate with external services (via MQTT and HTTP) while serving a local web interface through SPIFFS. It also includes OTA (over-the-air) update functionality.
- Key external libraries (ESPAsyncWebServer, ElegantOTA, ArduinoJson, ArduinoHttpClient, ThingsBoard, and MQTT client libraries) indicate that network connectivity, remote telemetry, and OTA updates are core to the project.

##### Analyzing the File Structure
- The top-level directories (include, lib, src, data, boards, test) reveal both the modular firmware code and supporting assets.
– The “src” directory contains the main.cpp and multiple task files (ServerTask, TaskGPS, TaskMQTT, TaskSensor, WifiTask, TaskModbus485) which represent distinct modules or threads.
– The “include” folder holds configuration headers (like Global_config.h) that likely provide global definitions.
– The “lib” directory contains external libraries divided into several submodules (ArduinoJson, ElegantOTA, ThingsBoard, etc.) that the firmware uses for communication, OTA, and JSON handling.
– The “data” directory contains HTML, JavaScript, and CSS files which serve as a web interface (loaded via SPIFFS).
- Other files such as platformio.ini and project_config.h.example are important for build and deployment configuration.

– Start with the Hardware layer (ESP board, connected sensors and communication interfaces).
– Next, illustrate a “Firmware” block subdivided into:
- Connectivity: “WiFi Task”
- Data and Sensor Management: “Sensor Task”, “GPS Task”, “Modbus485 Task”
- Communication: “MQTT Task” (linking to ThingsBoard) and “HTTP/OTA Module”
- User Interface: “Server Task” (serving web assets from SPIFFS)
- The Internet with an “MQTT Broker/Cloud Server (ThingsBoard)” block.
- A “Web Client” block connecting to the local web server.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Layer
    subgraph "Hardware Layer"
        ESP["ESP Board (ESP8266/ESP32)"]:::hardware
        Sensors["Sensors (Ultrasonic, GPS, etc.)"]:::hardware
        ESP --> Sensors
    end

    %% Firmware Layer
    subgraph "Firmware"
        %% Firmware Core
        subgraph "Firmware Core"
            GlobalConfig["Global Config Header"]:::config
            ProjectConfig["Project Config Example"]:::config
            MainFirmware["Main Firmware Code"]:::config
            BuildConfig["Build Configuration"]:::config
            GlobalConfig --> ProjectConfig
            ProjectConfig --> MainFirmware
            MainFirmware --> BuildConfig
        end

        %% Connectivity
        subgraph "Connectivity"
            WiFi["WiFi Task"]:::task
        end

        %% Data & Sensor Management
        subgraph "Data & Sensor Management"
            Sensor["Sensor Task"]:::task
            Modbus["Modbus485 Task"]:::task
            GPS["GPS Task"]:::task
            Sensor --> Modbus
        end

        %% Communication & OTA
        subgraph "Communication & OTA"
            MQTT["MQTT Task"]:::task
            OTA["OTA Update Module"]:::task
        end

        %% User Interface
        subgraph "User Interface"
            Server["Async Web Server"]:::task
            SPIFFS["Web Assets (SPIFFS)"]:::storage
            Server --> SPIFFS
        end

        %% Internal Connections
        WiFi -->|"provides_network"| MQTT
        WiFi -->|"provides_network"| Server
        Sensor -->|"sensor_data"| MQTT
        GPS -->|"gps_data"| MQTT
        WiFi --> OTA
    end

    %% External Systems
    subgraph "External Systems"
        Broker["MQTT Broker/Cloud (ThingsBoard)"]:::external
        WebClient["Web Client"]:::external
    end

    MQTT -->|"reports_telemetry"| Broker
    Server -->|"serves_UI"| WebClient

    %% External Libraries
    subgraph "External Libraries"
        ArduinoJson["ArduinoJson"]:::library
        ArduinoHttpClient["ArduinoHttpClient"]:::library
        ElegantOTA["ElegantOTA"]:::library
        ThingsBoard["ThingsBoard Integration"]:::library
    end

    MQTT --- ThingsBoard
    OTA --- ElegantOTA
    Server --- ArduinoHttpClient
    Server --- ArduinoJson

    %% Click Events for Firmware Core
    click GlobalConfig "https://github.com/aclab-hcmut/thesis_mdt263_weather_monitor/blob/main/include/Global_config.h"
    click ProjectConfig "https://github.com/aclab-hcmut/thesis_mdt263_weather_monitor/blob/main/project_config.h.example"
    click MainFirmware "https://github.com/aclab-hcmut/thesis_mdt263_weather_monitor/blob/main/src/main.cpp"
    click BuildConfig "https://github.com/aclab-hcmut/thesis_mdt263_weather_monitor/blob/main/platformio.ini"

    %% Click Events for Tasks
    click WiFi "https://github.com/aclab-hcmut/thesis_mdt263_weather_monitor/blob/main/src/Headers/WifiTask.h"
    click MQTT "https://github.com/aclab-hcmut/thesis_mdt263_weather_monitor/blob/main/src/Headers/TaskMQTT.h"
    click GPS "https://github.com/aclab-hcmut/thesis_mdt263_weather_monitor/blob/main/src/Headers/TaskGPS.h"
    click Sensor "https://github.com/aclab-hcmut/thesis_mdt263_weather_monitor/blob/main/src/tasks/TaskSensor.cpp"
    click Modbus "https://github.com/aclab-hcmut/thesis_mdt263_weather_monitor/blob/main/src/Headers/TaskModbus485.h"
    click Server "https://github.com/aclab-hcmut/thesis_mdt263_weather_monitor/blob/main/src/Headers/ServerTask.h"
    click SPIFFS "https://github.com/aclab-hcmut/thesis_mdt263_weather_monitor/blob/main/data/index.html"

    %% Click Events for External Libraries
    click ArduinoHttpClient "https://github.com/aclab-hcmut/thesis_mdt263_weather_monitor/tree/main/lib/ArduinoHttpClient"
    click ArduinoJson "https://github.com/aclab-hcmut/thesis_mdt263_weather_monitor/tree/main/lib/ArduinoJson"
    click ElegantOTA "https://github.com/aclab-hcmut/thesis_mdt263_weather_monitor/tree/main/lib/ElegantOTA"
    click ThingsBoard "https://github.com/aclab-hcmut/thesis_mdt263_weather_monitor/tree/main/lib/ThingsBoard"

    %% Styles
    classDef hardware fill:#f9c,stroke:#333,stroke-width:2px;
    classDef config fill:#bbf,stroke:#333,stroke-width:2px;
    classDef task fill:#bfb,stroke:#333,stroke-width:2px;
    classDef external fill:#fdd,stroke:#333,stroke-width:2px;
    classDef storage fill:#ffc,stroke:#333,stroke-width:2px;
    classDef library fill:#cfc,stroke:#333,stroke-width:2px;
```
