Core idea: Raspberry Pi runs all backend logic (cron jobs, data storage, evaluation, API endpoints). Static frontend deployed to tarhely.com. GitLab remains the code repository and development platform.
| Layer | Where | Responsibility |
|---|---|---|
| Code & Development | GitLab | Source repo, CI, dev preview (Pages), code review |
| Backend & Data | Raspberry Pi (home) | Cron, API calls, scoring, ranking, route log API, data storage |
| Frontend & Serving | tarhely.com | Static HTML/JS/CSS, public-facing, fast CDN |
| Component | Pi 4 (budget) | Pi 5 (recommended) |
|---|---|---|
| CPU | 4× Cortex-A72 @ 1.8GHz | 4× Cortex-A76 @ 2.4GHz |
| RAM | 4GB sufficient | 4GB sufficient (8GB future-proof) |
| Storage | 32GB microSD + USB SSD recommended | 32GB microSD + NVMe via HAT |
| Power | ~5W idle | ~7W idle |
| OS | Raspberry Pi OS Lite (64-bit) | Raspberry Pi OS Lite (64-bit) |
| Cost | ~€50-60 | ~€70-90 |
Storage recommendation: Use a USB SSD (even 128GB is fine) instead of only microSD. SD cards wear out with frequent writes (JSON files, logs). Boot from SD, store data on SSD.
The Pi sits behind your home router. For tarhely.com's route-weather.js to POST route logs to the Pi, the Pi needs to be reachable. Options:
| Method | Complexity | Best for |
|---|---|---|
| Dynamic DNS + port forward | Easy | If your ISP gives you a public IP. Forward port 443 to Pi. |
| Cloudflare Tunnel | Medium | No port forwarding needed. Free. Pi connects outbound to Cloudflare. |
| Tailscale/WireGuard | Medium | If only YOU need to reach the Pi (not public users). |
| Pi pushes to tarhely.com | Simplest | No inbound needed — Pi just rsyncs output. Route logs handled differently. |
Recommended: Cloudflare Tunnel (free)
cloudflared daemon → connects outbound to Cloudflareapi.yourdomain.com that proxies to Pihttps://api.yourdomain.com/log-routeIf you don't want to expose the Pi publicly:
# OS Raspberry Pi OS Lite 64-bit (Debian Bookworm based) # System packages sudo apt install python3 python3-venv git nginx rsync # Python environment python3 -m venv /opt/amfor-cast/venv source /opt/amfor-cast/venv/bin/activate /opt/amfor-cast/venv/bin/python3 -m pip install flask gunicorn markdown # Git identity (needed for pull --rebase and any commits) git config --global user.email "demogun@gmail.com" git config --global user.name "Attila Vigh" # Clone repo git clone https://gitlab.com/demogun1/misc_scripts.git /opt/amfor-cast/repo # Symlink data dir (on SSD) ln -s /mnt/ssd/amfor-data /opt/amfor-cast/data # Cloudflare tunnel (for public API) curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm64.deb -o cloudflared.deb sudo dpkg -i cloudflared.deb cloudflared tunnel login cloudflared tunnel create amfor-cast
# Pull latest code from GitLab (every 15 min) */15 * * * * cd /opt/amfor-cast/repo && git pull -r --quiet origin main # Hourly: pull + generate forecasts + history (skip scoring) 0 * * * * cd /opt/amfor-cast/repo && git pull -r && /opt/amfor-cast/venv/bin/python3 run-and-publish.py --skip-validator --output-dir /opt/amfor-cast/output --data-dir /opt/amfor-cast/data # Daily 07:00 CEST: save snapshot + evaluate + score 0 5 * * * cd /opt/amfor-cast/repo && git pull -r && /opt/amfor-cast/venv/bin/python3 run-and-publish.py --only-validator --force --data-dir /opt/amfor-cast/data # After each generation: sync output to tarhely.com 5 * * * * rsync -az --delete -e ssh /opt/amfor-cast/output/ amforcas@we050.tarhely.com:/home/amforcas/public_html/ # Weekly: prune old route logs (keep 90 days) 0 3 * * 0 find /opt/amfor-cast/data/route-logs -name "*.json" -mtime +90 -delete
# /opt/amfor-cast/api/app.py
from flask import Flask, request, jsonify
from pathlib import Path
from datetime import datetime
import json, uuid
app = Flask(__name__)
ROUTE_LOGS_DIR = Path("/opt/amfor-cast/data/route-logs")
@app.route("/api/log-route", methods=["POST"])
def log_route():
"""Receive route forecast data from client-side route planner."""
data = request.get_json()
if not data or "waypoints" not in data:
return jsonify({"error": "Invalid payload"}), 400
filename = f"{datetime.now().strftime('%Y-%m-%d')}_route_{uuid.uuid4().hex[:8]}.json"
ROUTE_LOGS_DIR.mkdir(parents=True, exist_ok=True)
(ROUTE_LOGS_DIR / filename).write_text(json.dumps(data, indent=2))
return jsonify({"status": "ok", "id": filename}), 201
@app.route("/api/health", methods=["GET"])
def health():
return jsonify({"status": "ok", "timestamp": datetime.now().isoformat()})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
# /etc/systemd/system/amfor-api.service [Unit] Description=Amfor-Cast Route Log API After=network.target [Service] Type=simple User=pi WorkingDirectory=/opt/amfor-cast/api ExecStart=/opt/amfor-cast/venv/bin/gunicorn -w 2 -b 127.0.0.1:5000 app:app Restart=always [Install] WantedBy=multi-user.target
# /etc/nginx/sites-available/amfor-api
server {
listen 8080;
server_name localhost;
location /api/ {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location / {
root /opt/amfor-cast/output;
index index.html;
}
}
| Change | Why |
|---|---|
Add --output-dir flag to run-and-publish.py | Output goes to /opt/amfor-cast/output/ not public_html/ |
Add --data-dir flag to all scripts | Data lives on SSD, not in repo |
| Update route-weather.js API URL | POST to https://api.yourdomain.com/log-route |
| Remove scp deploy from run-and-publish.py | Replaced by rsync cron |
| Remove git push deploy | Pi pushes via rsync, not git |
Add .gitignore for data/ and output/ | Data stays on Pi, not in repo |
Checklist before exposing Pi to internet:
pi password / use SSH keys onlysudo apt update && sudo apt upgrade weekly| What | How |
|---|---|
| Pi alive? | UptimeRobot (free) pings /api/health every 5 min |
| Cron ran? | Check output file timestamps; alert if >2h stale |
| Disk space | Cron: df -h → alert if >80% |
| Temperature | vcgencmd measure_temp → log + alert if >70°C |
| Auto-restart | Systemd restart-on-failure for API service |
| Power failure | UPS (optional, €30) or accept ~1h data gap on rare outages |
| Item | Pi setup (one-time) | Monthly |
|---|---|---|
| Raspberry Pi 5 (4GB) | €70 | — |
| microSD 32GB + USB SSD 128GB | €35 | — |
| Power supply + case | €25 | — |
| Electricity (~7W) | — | ~€1.50 |
| tarhely.com hosting | — | ~€3-5 |
| Cloudflare Tunnel | — | Free |
| Domain (optional) | — | ~€1/month |
| Total | ~€130 | ~€5-7/month |
run-and-publish.py --dry-run--output-dir and --data-dir flags to scriptsNo big-bang migration needed. Run both in parallel, cut over gradually: