Parsel bahçesinde ev WiFi'si ile telefon hotspot'u arasında geçiş yapan Pi ağ geçidi
Yapay zekâ tarafından English dilinden çevrildi ·
Merhaba herkese. Cumartesileri topluluk bahçemizde toprak nemini ve birkaç DS18B20 sensörünü okuyan bir Pi 4’üm var; haftanın geri kalanında ise evde tezgâhta sera sensörlerini okuyor. Verileri paho-mqtt ile Hermetry’ye gönderiyor.Sorun: Pi yalnızca ev WiFi’me bağlanabiliyor. Bahçede telefonumdaki hotspot’u açıyorum ama Pi bağlanamıyor, bu yüzden o gün Hermetry’de hiçbir veriyle eve dönüyorum. Bir rehberi takip ettim ve her iki ağı da priority= ile /etc/wpa_supplicant/wpa_supplicant.conf dosyasına ekledim, ancak dosya yok sayılıyor gibi görünüyor.
$ cat /etc/os-release | head -1
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
$ nmcli -t -f NAME,TYPE con show
preconfigured:802-11-wireless
lo:loopback
İkinci konu da ilgili: Pi bir süre çevrimdışı kalırsa okumaları saklayıp daha sonra gönderebilir miyim? Şu anda yayınlama başarısız olduğunda betik okumaları atıyor.
Hi all. I have a Pi 4 that reads soil moisture and a couple of DS18B20s at our community allotment on Saturdays, and the rest of the week it sits at home on the bench reading the greenhouse sensors. It publishes to Hermetry with paho-mqtt.
Problem: it only ever connects to my home WiFi. At the allotment I turn on the hotspot on my phone and the Pi just doesn’t join, so I come home with nothing in Hermetry for that day. I followed a guide and put both networks in /etc/wpa_supplicant/wpa_supplicant.conf with priority=, but it looks like the file is ignored.
$ cat /etc/os-release | head -1
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
$ nmcli -t -f NAME,TYPE con show
preconfigured:802-11-wireless
lo:loopback
Second thing, related: if it’s offline for a bit, can I keep the readings and send them later? Right now the script just drops them when publish fails.
Yapay zekâ tarafından English dilinden çevrildi ·
Bookworm artık NetworkManager kullanıyor, bu yüzden wpa_supplicant.conf dosyası artık okunmuyor. Yapılacak yol nmcli.
Bookworm uses NetworkManager now, so wpa_supplicant.conf isn’t read anymore. nmcli is the way.
Yapay zekâ tarafından English dilinden çevrildi ·
Kevin haklı, ve “preconfigured” bağlantısı, imager’ın ev WiFi’nizden oluşturduğu bağlantıdır. Hotspot’u ikinci bir NetworkManager bağlantısı olarak ekleyin ve ikisine de öncelik verin. Ben tam olarak bu yapıyla iki fabrika arasında bir Pi taşıyorum.
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
İkisi de menzildeyse yüksek öncelikli olan kazanır, yani önce ev. Pi’yi açmadan önce hotspot’u açın; Pi önce açılırsa bir dakika bekleyin, NetworkManager yeniden tarar.Tamponlama için okumaları küçük bir SQLite tablosunda veya hatta bir JSONL dosyasında tutun ve bağlantı geri geldiğinde bunları kendi zaman damgalarıyla, toplu halde gönderin:
[{"ts": 1762668000000, "values": {"soil.bed3": 31.5, "air.temp": 12.1}},
{"ts": 1762668300000, "values": {"soil.bed3": 31.2, "air.temp": 12.6}}]
ts, UTC cinsinden milisaniyedir. Bir satırı yalnızca yayın onaylandıktan sonra silin (QoS 1, paho ile wait_for_publish() kullanarak PUBACK’i bekleyin).Pi ile ilgili bir tuzak: pilli bir saat yoktur. Allotment’ta açılır ve bir süre ağ alamazsa, NTP senkronize olana kadar saat yanlıştır; bu saatle damgalanan okumalar yanlış zamana düşer ya da atılır (10 dakikadan fazla ileri tarihliyse reddedilir). Okumaları yalnızca timedatectl show -p NTPSynchronized evet dediğinde damgalayın; aksi halde ts olmadan gönderin ve Hermetry’nin varış zamanını kullanmasına izin verin.
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.
Yapay zekâ tarafından English dilinden çevrildi ·
Tam da bu sebeple ucuz bir RTC HAT aldım, DS3231, birkaç sterline. Böylece saat internet olmasa bile doğru oluyor.
I bought a cheap RTC HAT for this exact reason, DS3231, a couple of quid. Then the clock is right even offline.
Yapay zekâ tarafından English dilinden çevrildi ·
Ayrıca toplu gönderimleri makul tutun; varsayılan değer cihaz başına saniyede 10 mesajdır. Tek seferde büyük bir birikim gönderilirse mesajlar düşürülür.
And keep the batches reasonable, the default is 10 messages a second per device. A big backlog in one go gets dropped.
Yapay zekâ tarafından English dilinden çevrildi ·
Çözüldü. tsmith’in yazdığı gibi hotspot’u nmcli ile ekledim, öncelikler 20/10. Cumartesi günü açılıştan yaklaşık 40 sn sonra telefona bağlandı. Telefonun uzak bölmelerde sinyali yokken okumalar bir JSONL dosyasına yazıldı, sinyal geri gelince 50’lik gruplar halinde yukarı gönderildi. İlk hafta ilk birkaç okumada saatler bir saat kaymıştı, tam olarak NTP meselesi; bu yüzden Michael’ın yaptığı gibi bir DS3231 sipariş ettim. O gelene kadar script, zaman damgası basmadan önce NTPSynchronized değerini kontrol ediyor.
Sorted. Added the hotspot with nmcli as tsmith wrote, priorities 20/10. Saturday it joined the phone within about 40 s of boot. Readings went into a JSONL file while the phone had no signal at the far beds, then went up in batches of 50 when it came back. First week the times were off by an hour on the first few readings, the NTP thing exactly, so I’ve ordered a DS3231 like Michael. Until it comes the script checks NTPSynchronized before stamping.
- Bu konuyu yanıtlamak için giriş yapmış olmalısınız.
Sohbete katılın
Soru sormak ve yanıtlamak, yararlı gönderileri beğenmek ve sorununuzu çözen yanıtı işaretlemek için oturum açın. Her katkı puan ve seviye kazandırır.

