# hubeek/raspiservertemp architecture

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

- Interactive diagram: https://gitdiagram.com/hubeek/raspiservertemp
- Repository: https://github.com/hubeek/raspiservertemp

## Overview

##### Project type and purpose
- This is a lightweight, Raspberry Pi–based IoT monitoring and control system comprised of standalone Python scripts, each scheduled via cron.
- Its responsibilities are:
- Periodically ping a list of servers to check availability (servertest.py)
- Measure local temperature from a sensor, compare against a stored thermostat setpoint in a database, and switch a heater on or off (temperature.py)
- Fetch external weather data from a public API (weatherapi.py)
- Optionally clean up URL entries or stale records (cleanupurls.py)
- test.py contains your unit or integration tests.

##### File structure
- Flat layout: six scripts + README. No monolithic application server or UI layer.
- Each script is its own “micro-job,” triggered by cron every five minutes.
- No build system or dependency directories—this runs directly under the Pi’s Python environment.

##### README for additional insights
- Confirms three primary cron jobs at 5-minute intervals
- Mentions a thermostat value stored in “db” (likely SQLite or similar local DB).
- Suggests future “cleanup in cron” for cleanupurls.py.

##### Main components and interactions
a. Scheduler Layer
- Cron daemon on Raspberry Pi
- servertest.py – uses ICMP or HTTP to check remote servers
- weatherapi.py – makes HTTP request to external weather API provider
- temperature.py – reads from a DS18B20 (or GPIO) sensor, queries local DB, toggles heater via GPIO
- cleanupurls.py – purges/updates URL records in local DB
c. Data and persistence
- Thermostat Database – holds setpoint and maybe historical readings
d. Hardware interfaces
- Temperature sensor (GPIO)
- Heater actuator (GPIO or relay)
e. External services
- Monitored servers (by IP or URL)
- Public weather API endpoint

##### Relationships and data flows
- Cron → (5 min) → each Python script
- servertest.py → Network → Remote servers → Logs results → (optional) local DB or log file
- weatherapi.py → HTTP → Weather API → Writes data → local DB
- temperature.py → Sensor read → Temperature value → compare with DB setpoint → GPIO → Heater on/off → update DB or log
- cleanupurls.py → DB → Deletes stale entries → Writes back

##### Architectural patterns and design principles
- Simple “cron‐triggered batch jobs” pattern
- Single‐responsibility scripts: each module does one job
- Clear separation between hardware I/O (temperature, heater), network I/O (servers, weather), and data persistence
- Scripts can be independently tested (test.py) and maintained

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Scheduler
    Cron["Cron Daemon"]:::scheduler

    %% Tasks Layer
    subgraph "Tasks"
        st["servertest.py"]:::script
        wa["weatherapi.py"]:::script
        tp["temperature.py"]:::script
        cl["cleanupurls.py"]:::script
        ts["test.py"]:::script
    end

    %% Persistence
    DB["Thermostat DB (SQLite)"]:::persistence

    %% Hardware Interfaces
    Sensor["Temperature Sensor (DS18B20)"]:::hardware
    Heater["Heater Actuator (Relay)"]:::hardware

    %% External Services
    Servers["Monitored Servers"]:::external
    WeatherAPI["Weather API Endpoint"]:::external

    %% Connections
    Cron -->|"every 5 min"| st
    Cron -->|"every 5 min"| wa
    Cron -->|"every 5 min"| tp
    Cron -->|"every 5 min"| cl
    Cron -->|"every 5 min"| ts

    st -->|"ICMP/HTTP"| Servers
    st -->|"write results"| DB

    wa -->|"HTTP GET"| WeatherAPI
    wa -->|"write data"| DB

    Sensor -->|"GPIO Read"| tp
    tp -->|"DB Query"| DB
    tp -->|"GPIO Write"| Heater
    tp -->|"update log"| DB

    cl -->|"delete stale entries"| DB

    %% Legend
    subgraph "Legend"
        cronLegend["Scheduler"]:::scheduler
        scriptLegend["Scripts"]:::script
        persistenceLegend["Persistence"]:::persistence
        hardwareLegend["Hardware"]:::hardware
        externalLegend["External Services"]:::external
    end

    %% Click Events
    click Cron "https://github.com/hubeek/raspiservertemp/blob/main/README.md"
    click st "https://github.com/hubeek/raspiservertemp/blob/main/servertest.py"
    click wa "https://github.com/hubeek/raspiservertemp/blob/main/weatherapi.py"
    click tp "https://github.com/hubeek/raspiservertemp/blob/main/temperature.py"
    click cl "https://github.com/hubeek/raspiservertemp/blob/main/cleanupurls.py"
    click ts "https://github.com/hubeek/raspiservertemp/blob/main/test.py"

    %% Styles
    classDef scheduler fill:#AED6F1,stroke:#1B4F72,color:#1B4F72;
    classDef script fill:#A9DFBF,stroke:#196F3D,color:#196F3D;
    classDef persistence fill:#F9E79F,stroke:#B7950B,color:#B7950B;
    classDef hardware fill:#F5CBA7,stroke:#A04000,color:#A04000;
    classDef external fill:#D7BDE2,stroke:#6C3483,color:#6C3483;
```
