Python scripts and JSON feeds

FastAPI relay services, Redis caching, and Python tooling that sit between probes and the dashboard.

Close-up of white Cat-5e Ethernet cables with RJ45 connectors
Probe JSON usually leaves the LAN over Ethernet or a nearby relay, not the public internet directly. Photo: DiscDepotDundee.co.uk. CC BY-SA 4.0

Microcontrollers excel at reading probes; Python excels at caching, authentication, and serving stable HTTPS endpoints. The fast-api-relay project sits between Arduino JSON and the Astro site, normalizing responses and reducing load on fragile embedded stacks.

Why a relay layer helps

Direct browser fetches to a LAN IP address break when DNS changes, certificates expire, or the home uplink drops. A relay on a VPS or cloud worker presents one consistent URL, adds Redis caching so dashboards do not hammer the probe, and can aggregate multiple sites if you expand beyond a single property.

FastAPI responsibilities

  • Accept upstream fetches from the Arduino or local network agent on a schedule.
  • Store the latest payload in Redis with a short TTL.
  • Serve GET /... responses instantly from cache for the website.
  • Log stale data when upstream stops updating: useful for alerting.

Example consumer fetch

The Astro site’s fetch layer requests your configured HTTPS URL, parses the temp object (or auto-detects SenML / Home Assistant REST JSON when that root is missing), and maps keys to dashboard probes. The same URL can power Node scripts, Grafana JSON plugins, or Home Assistant REST sensors.

Browser JSON viewer showing temp probe keys 0, 1, and avg with Fahrenheit Celsius and humidity
Example relay payload shape the website expects after caching upstream Arduino JSON.
# Periodic upstream pull (cron or asyncio task)
import httpx

UPSTREAM = "http://192.168.1.50/temp.json"
response = httpx.get(UPSTREAM, timeout=5.0)
response.raise_for_status()
cache.set("garage:latest", response.text)

Operational scripts

Beyond the API, small Python utilities validate JSON schema, backfill CSV archives, or compare probe averages against OpenWeather forecasts. Because probes expose plain JSON, you can prototype analytics in a notebook before promoting logic into production services.

Repository reference

Implementation details, Redis configuration, and deployment notes for the relay are maintained in fast-api-relay. Configure the public relay URL in your temperature feed settings after signing in.

Uno Ethernet: HTTP→HTTPS for push ingest

A W5100 shield cannot POST to https://probeharbor.dev. The stdlib relay sketches/relay/push_https_forward.py listens for HTTP from the Arduino and forwards the same path and body over HTTPS. Pair it with ethernet_dht22_ingest (DHT22 on A4/A5, classic temp JSON).

python3 sketches/relay/push_https_forward.py --listen 0.0.0.0:8080 \
  --upstream https://probeharbor.dev