# vohoangdinhkha/weather_station architecture

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

## Overview

##### Main Components
- Hardware Modules:
- ESP32 Microcontroller: Serves as the central unit running the firmware.
- ILI9225 TFT Display: Communicates over SPI to render interfaces and graphics.
- Sensors and Modules: DHT22 sensor for temperature/humidity, DS1307 RTC for time keeping.
- Input and Output: A physical button (to switch between display interfaces) and a buzzer (for the alarm).
- Communication: Wi-Fi module integrated in ESP32 for network connectivity; this is used to retrieve time-update from an NTP server and weather data via the OpenWeather API.
- External Platforms: The E-RA platform that displays results on the Web/Mobile.

- Software/Firmware Components:
- Main Application: “Mini_Project.ino” drives the overall logic including switching between interfaces.
- FreeRTOS Tasks: The project uses FreeRTOS to handle concurrent tasks like LED light control and data uploads.

##### Relationships and Interactions
- The central ESP32 communicates with peripheral hardware (sensors, RTC, display, button, buzzer) and external services.
- Data flows:
- Sensor Data Flow: DHT22 sensor readings → ESP32.
- Time Data Flow: DS1307 (and NTP updates when available) → ESP32.
- API Communication: ESP32 connects over Wi-Fi to retrieve weather data from the OpenWeather API.
- Data Presentation: Processed sensor, time, moon phase, and weather data flow from the ESP32 through the SPI protocol → ILI9225 TFT Display.
- User Interaction: Button press events are captured by the ESP32 to toggle between two interfaces.
- FreeRTOS tasks schedule concurrent operations (LEDs and data upload to the E-RA platform).

##### Architectural Patterns and Design Principles
- Modular Design: Even though there are only a few files, the project logically separates concerns (display management, sensor handling, communication).
- Real-Time Processing: With time-sensitive updates from the RTC, sensors, and API calls.
- Concurrency: Use of FreeRTOS ensures tasks are handled concurrently.

- DHT22 sensor and DS1307 RTC module directly to the ESP32.
- Button as a physical input to the ESP32.
- Buzzer linked for the alarm function.
- External connections:
- Link Wi-Fi from the ESP32 to the NTP server and OpenWeather API.
- ESP32 to an “E-RA Platform” block to represent data uploads for mobile/web display.
- Inside the ESP32 block (or as a separate software layer), show the major tasks scheduled by FreeRTOS and the logical separation of display updates, sensor reading, and network communications.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Layer
    subgraph "Hardware Layer"
        ESP32["ESP32 Microcontroller"]:::hardware
        Display["ILI9225 TFT Display (SPI)"]:::hardware
        DHT22["DHT22 Sensor"]:::hardware
        RTC["DS1307 RTC Module"]:::hardware
        Button["Button"]:::hardware
        Buzzer["Buzzer"]:::hardware
        WiFi["Wi-Fi Module"]:::hardware
        NTP["NTP Server"]:::external
        OpenWeather["OpenWeather API"]:::external
        ERA["E-RA Platform"]:::external
    end

    %% Software/Firmware Layer
    subgraph "Software Layer"
        MainFirmware["Main Firmware (Mini_Project.ino)"]:::software
        LoadingFrames["Loading_Frames.h"]:::software
        WeatherMoon["Weather-Moon_Icons.h"]:::software
        ImgMap["img_map.h"]:::software
        FreeRTOS["FreeRTOS Tasks (LED Control,Data Upload)"]:::rtos
    end

    %% Hardware connections
    ESP32 -->|"SPI"| Display
    DHT22 -->|"sensor"| ESP32
    RTC -->|"time"| ESP32
    Button -->|"input"| ESP32
    ESP32 -->|"alarm"| Buzzer
    ESP32 -->|"Wi-Fi"| WiFi
    WiFi -->|"sync"| NTP
    WiFi -->|"weather"| OpenWeather
    ESP32 -->|"upload"| ERA

    %% Integration between Hardware and Software
    ESP32 -->|"runs"| MainFirmware

    %% Software layer interactions
    MainFirmware -->|"display"| LoadingFrames
    MainFirmware -->|"graphics"| WeatherMoon
    MainFirmware -->|"graphics"| ImgMap
    MainFirmware -->|"RTOS"| FreeRTOS

    %% Click Events
    click ESP32 "https://github.com/vohoangdinhkha/weather_station/blob/main/Mini_Project.ino"
    click MainFirmware "https://github.com/vohoangdinhkha/weather_station/blob/main/Mini_Project.ino"
    click LoadingFrames "https://github.com/vohoangdinhkha/weather_station/blob/main/Loading_Frames.h"
    click WeatherMoon "https://github.com/vohoangdinhkha/weather_station/blob/main/Weather-Moon_Icons.h"
    click ImgMap "https://github.com/vohoangdinhkha/weather_station/blob/main/img_map.h"
    click FreeRTOS "https://github.com/vohoangdinhkha/weather_station/blob/main/Mini_Project.ino"

    %% Styles
    classDef hardware fill:#b3d9ff,stroke:#1F618D,stroke-width:2px;
    classDef software fill:#d1f2eb,stroke:#148F77,stroke-width:2px;
    classDef external fill:#fcf3cf,stroke:#B7950B,stroke-width:2px;
    classDef rtos fill:#f7c6c7,stroke:#CB4335,stroke-width:2px;
```
