From c5cba6a318cf4f44e40be4c6747e0c3f64a2419e Mon Sep 17 00:00:00 2001 From: nicoboy Date: Mon, 20 Jul 2026 19:02:41 +0200 Subject: [PATCH] =?UTF-8?q?Lire=20wifi=5Fchannel=20depuis=20/etc/wifibroad?= =?UTF-8?q?cast.cfg=20au=20d=C3=A9marrage=20(robustesse)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- receive_cam.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/receive_cam.py b/receive_cam.py index 43a24cd..86efaae 100644 --- a/receive_cam.py +++ b/receive_cam.py @@ -91,12 +91,30 @@ def sideband_loop() -> None: print("[SIDEBAND] Arrêt.") +def read_band_label() -> str: + """Lit wifi_channel depuis /etc/wifibroadcast.cfg (local, fichier + système) pour déterminer la bande. Lu une seule fois au démarrage + — la bande ne change qu'via switch_band.sh, qui redémarre ce + service de toute façon.""" + try: + with open("/etc/wifibroadcast.cfg") as f: + for line in f: + line = line.strip() + if line.startswith("wifi_channel"): + # ex: "wifi_channel = 6 # commentaire" + val = line.split("=", 1)[1].split("#")[0].strip() + ch = int(val) + return "2.4GHz" if ch <= 14 else "5GHz" + except (FileNotFoundError, ValueError, IndexError) as e: + print(f"[BAND] Impossible de lire wifi_channel : {e}") + return "?" + + def rssi_loop() -> None: """Écoute l'API JSON wfb-ng locale (127.0.0.1:8103), extrait le RSSI du flux vidéo dédié (id="video rx") et le stocke pour l'overlay. - Capture aussi wifi_channel au démarrage pour afficher la bande. Reconnexion automatique en cas de coupure (wfb-server-gs redémarré).""" - global _rssi_data, _band_label + global _rssi_data buf = "" while _running: try: @@ -117,10 +135,6 @@ def rssi_loop() -> None: d = json.loads(line) except json.JSONDecodeError: continue - # Capture wifi_channel au démarrage (dans le message "settings") - if "common" in d and "wifi_channel" in d["common"]: - ch = d["common"]["wifi_channel"] - _band_label = "2.4GHz" if ch <= 14 else "5GHz" if d.get("id") == "video rx": ants = d.get("rx_ant_stats") or [] if ants: @@ -385,7 +399,11 @@ class MJPEGHandler(BaseHTTPRequestHandler): def main(): - global _running + global _running, _band_label + + # 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.add_argument("--no-yolo", action="store_true", help="Désactiver l'inférence YOLOv8 (flux brut)")