How hubeek/raspiservertemp works
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