New: the AI firewall watches the whole platform and explains each incident in plain words. See how it works

Reply To: Pi gateway that moves between home WiFi and a phone hotspot at the allotment

Kevin’s right, and the “preconfigured” connection is the one the imager created from your home WiFi. Add the hotspot as a second NetworkManager connection and give both a priority. I carry a Pi between two factories with exactly this.

sudo nmcli con add type wifi ifname wlan0 con-name allotment 
     ssid "Aisha-phone" wifi-sec.key-mgmt wpa-psk wifi-sec.psk "********"
sudo nmcli con modify allotment connection.autoconnect yes connection.autoconnect-priority 10
sudo nmcli con modify preconfigured connection.autoconnect-priority 20
nmcli -f NAME,AUTOCONNECT,AUTOCONNECT-PRIORITY con show

Higher priority wins when both are in range, so home first. Turn the hotspot on before you power the Pi; if it boots first, give it a minute, NetworkManager rescans.

For buffering: keep the readings in a small SQLite table or even a JSONL file, and when the connection comes back send them with their own time stamps, in batches:

[{"ts": 1762668000000, "values": {"soil.bed3": 31.5, "air.temp": 12.1}},
 {"ts": 1762668300000, "values": {"soil.bed3": 31.2, "air.temp": 12.6}}]

ts is milliseconds UTC. Delete a row only after the publish is acknowledged (QoS 1, wait for the PUBACK in paho with wait_for_publish()).

One trap with a Pi: there’s no battery-backed clock. If it boots at the allotment and gets no network for a while, the clock is wrong until NTP syncs, and readings stamped with that clock end up at the wrong time or get dropped (more than 10 minutes in the future is refused). Only stamp readings after timedatectl show -p NTPSynchronized says yes, otherwise send them without ts and let Hermetry use the arrival time.

Ground loops are my cardio.
Accepted solution♥ 3