# tsjakka/weatherstation architecture

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

- Interactive diagram: https://gitdiagram.com/tsjakka/weatherstation
- Repository: https://github.com/tsjakka/weatherstation

## Overview

##### Project type and purpose
- This is an embedded‐firmware/IoT project: an ESP32‐based outdoor sensor unit that reads multiple meteo sensors, aggregates data, and transmits RF packets to an Alecto display. It also supports OTA updates over Wi-Fi.

##### File structure
- Top level:
- LICENSE, README.md, Parts List, Photos (hardware documentation)
- Source/ – all firmware code:
– WeatherStation.ino (main Arduino sketch)
– SensorBase.{cpp,h} (abstract sensor driver layer)
– RFMxx.{cpp,h} (RF transceiver driver)
– Thies.{cpp,h}, WH1080.{cpp,h} (sensor‐specific drivers)
– Board and libraries.txt, project files for Visual Studio (.sln, .vcxproj)

##### Extract insights from the README
- Hardware components: ESP32, BME280 (I²C), DCF1 time receiver (digital input), RFM69HW RF transceiver (SPI or bit‐banged), Thiess anemometer (pulse/interrupt), original rain gauge (pulse).
- Software features: per‐sensor readers, WMO‐compliant wind aggregation, RF packet builder, 48 s transmission interval, Wi-Fi OTA updates (requires special GPIO considerations).

##### Main components and their relationships
a. Hardware layer
- Power supply (230 VAC → 3.3 V regulator, optional solar input)
- ESP32 microcontroller (central host)
- BME280 (I²C bus)
- DCF1 receiver (GPIO digital input, timestamp interrupts)
- Anemometer (GPIO pulse interrupt)
- Rain meter (GPIO pulse interrupt)
- RFM69HW transceiver (SPI or bit-banged serial interface)
- Original Alecto display (receives 433 MHz RF)

b. Firmware/software layer
- Sensor drivers (SensorBase subclasses: Thies, WH1080, BME280, DCF1)
- Data aggregation module (calculates wind speed/direction statistics)
- RF packet builder (formats according to Fine Offset protocol)
- RF transmission scheduler (sends every 48 s)
- OTA update manager (Wi-Fi initialization on double reboot)
- Arduino/FreeRTOS runtime

c. External services
- Wi-Fi network + OTA update server (could be over HTTP or ArduinoOTA)
- End‐user Alecto display (receives RF)

##### Architectural patterns and design principles
- Layered drivers: SensorBase abstract class → concrete sensor modules
- Separation of concerns: hardware drivers vs. data processing vs. communication
- Event/interrupt‐driven inputs for pulse sensors and time receiver
- Scheduler/timer for periodic transmission
- Fail‐safe OTA: gated Wi-Fi activation to not break anemometer GPIO

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Hardware Layer
    subgraph "Hardware Layer"
        PS["Power Supply"]:::hw
        MCU["ESP32-WROOM-32"]:::hw
        BME["BME280 (I²C)"]:::hw
        DCF["DCF1 Receiver"]:::hw
        WIND["Thies Anemometer"]:::hw
        RAIN["Rain Gauge"]:::hw
        RFHW["RFM69HW Transceiver"]:::hw
    end

    %% Firmware Stack on ESP32
    subgraph "Firmware Stack (on ESP32)"
        direction TB
        MS["WeatherStation.ino"]:::fw
        AR["Arduino/FreeRTOS Runtime"]:::fw
        subgraph "Sensor Drivers"
            SB["SensorBase"]:::fw
            THI["Thies Driver"]:::fw
            WH["WH1080 Driver"]:::fw
        end
        AGG["Data Aggregation Module"]:::fw
        PACK["RF Packet Builder"]:::fw
        SCH["RF Transmission Scheduler"]:::fw
        OTA["OTA Update Manager"]:::fw
    end

    %% External Services
    subgraph "External Services"
        WiFi["Wi-Fi/OTA Server"]:::ext
        DISP["Alecto Display"]:::ext
    end

    %% Project Files
    subgraph "Project Files"
        BC["Board & libraries.txt"]:::doc
        BL["VS Project Files"]:::doc
        DOC["Hardware Documentation"]:::doc
    end

    %% Connections - Hardware
    PS --> MCU
    MCU -->|I²C SDA/SCL| BME
    MCU -->|Interrupt_IN| DCF
    MCU -->|Interrupt_IN| WIND
    MCU -->|Interrupt_IN| RAIN
    MCU -->|SPI_MOSI/MISO/SCK| RFHW

    %% Connections - Software Stack
    MS --> AR
    AR --> SB
    SB --> THI
    SB --> WH
    THI --> AGG
    WH --> AGG
    AGG --> PACK
    PACK --> SCH
    SCH --> OTA

    %% Connections - Comms
    SCH -->|<48s interval| RFHW
    OTA -.->|HTTP/ArduinoOTA| WiFi
    RFHW -.->|433 MHz RF| DISP

    %% Connections - Project Files
    BC --> MS
    BL --> MS
    DOC --> PS

    %% Click Events
    click MS "https://github.com/tsjakka/weatherstation/blob/master/Source/WeatherStation.ino"
    click SB "https://github.com/tsjakka/weatherstation/blob/master/Source/SensorBase.h"
    click SB "https://github.com/tsjakka/weatherstation/blob/master/Source/SensorBase.cpp"
    click THI "https://github.com/tsjakka/weatherstation/blob/master/Source/Thies.h"
    click THI "https://github.com/tsjakka/weatherstation/blob/master/Source/Thies.cpp"
    click WH "https://github.com/tsjakka/weatherstation/blob/master/Source/WH1080.h"
    click WH "https://github.com/tsjakka/weatherstation/blob/master/Source/WH1080.cpp"
    click RFHW "https://github.com/tsjakka/weatherstation/blob/master/Source/RFMxx.h"
    click RFHW "https://github.com/tsjakka/weatherstation/blob/master/Source/RFMxx.cpp"
    click BC "https://github.com/tsjakka/weatherstation/blob/master/Source/Board and libraries.txt"
    click BL "https://github.com/tsjakka/weatherstation/blob/master/Source/WeatherStation.sln"
    click BL "https://github.com/tsjakka/weatherstation/blob/master/Source/WeatherStation.vcxproj"
    click BL "https://github.com/tsjakka/weatherstation/blob/master/Source/WeatherStation.vcxproj.filters"
    click DOC "https://github.com/tsjakka/weatherstation/blob/master/Parts List.txt"
    click DOC "https://github.com/tsjakka/weatherstation/tree/master/Photos/"
    click DOC "https://github.com/tsjakka/weatherstation/blob/master/README.md"
    click DOC "https://github.com/tsjakka/weatherstation/tree/master/LICENSE"

    %% Styles
    classDef hw fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef fw fill:#d4edda,stroke:#333,stroke-width:1px
    classDef ext fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef doc fill:#f8d7da,stroke:#333,stroke-width:1px
```
