Relire wifi_channel toutes les 10s pour mise à jour auto après switch_band.sh

This commit is contained in:
nicoboy
2026-07-20 19:32:09 +02:00
parent d32ad8c94e
commit 07b0b8c1b5

View File

@ -91,23 +91,27 @@ def sideband_loop() -> None:
print("[SIDEBAND] Arrêt.") print("[SIDEBAND] Arrêt.")
def read_band_label() -> str: def band_label_loop() -> None:
"""Lit wifi_channel depuis /etc/wifibroadcast.cfg (local, fichier """Relit /etc/wifibroadcast.cfg toutes les 10s pour détecter un
système) pour déterminer la bande. Lu une seule fois au démarrage changement de bande (ex: après switch_band.sh) sans jamais avoir
— la bande ne change qu'via switch_band.sh, qui redémarre ce besoin de redémarrer ce service."""
service de toute façon.""" global _band_label
try: while _running:
with open("/etc/wifibroadcast.cfg") as f: try:
for line in f: with open("/etc/wifibroadcast.cfg") as f:
line = line.strip() for line in f:
if line.startswith("wifi_channel"): line = line.strip()
# ex: "wifi_channel = 6 # commentaire" if line.startswith("wifi_channel"):
val = line.split("=", 1)[1].split("#")[0].strip() val = line.split("=", 1)[1].split("#")[0].strip()
ch = int(val) ch = int(val)
return "2.4GHz" if ch <= 14 else "5GHz" new_label = "2.4GHz" if ch <= 14 else "5GHz"
except (FileNotFoundError, ValueError, IndexError) as e: if new_label != _band_label:
print(f"[BAND] Impossible de lire wifi_channel : {e}") print(f"[BAND] Changement détecté : {_band_label} -> {new_label}")
return "?" _band_label = new_label
break
except (FileNotFoundError, ValueError, IndexError) as e:
print(f"[BAND] Impossible de lire wifi_channel : {e}")
time.sleep(10)
def rssi_loop() -> None: def rssi_loop() -> None:
@ -399,11 +403,7 @@ class MJPEGHandler(BaseHTTPRequestHandler):
def main(): def main():
global _running, _band_label global _running
# Détecte la bande radio au démarrage (depuis le fichier système)
_band_label = read_band_label()
print(f"[BAND] Bande détectée : {_band_label}")
parser = argparse.ArgumentParser(description="WireClaw — réception caméra + YOLOv8") parser = argparse.ArgumentParser(description="WireClaw — réception caméra + YOLOv8")
parser.add_argument("--no-yolo", action="store_true", help="Désactiver l'inférence YOLOv8 (flux brut)") parser.add_argument("--no-yolo", action="store_true", help="Désactiver l'inférence YOLOv8 (flux brut)")
@ -425,6 +425,10 @@ def main():
tr = threading.Thread(target=rssi_loop, daemon=True) tr = threading.Thread(target=rssi_loop, daemon=True)
tr.start() tr.start()
# Thread bande : relit wifi_channel toutes les 10s pour détecter les changements
tb = threading.Thread(target=band_label_loop, daemon=True)
tb.start()
# Thread de fond : connexion/reconnexion continue au flux GStreamer réel # Thread de fond : connexion/reconnexion continue au flux GStreamer réel
tg = threading.Thread(target=gstreamer_watcher, daemon=True) tg = threading.Thread(target=gstreamer_watcher, daemon=True)
tg.start() tg.start()