Relire wifi_channel toutes les 10s pour mise à jour auto après switch_band.sh
This commit is contained in:
@ -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
|
||||||
|
while _running:
|
||||||
try:
|
try:
|
||||||
with open("/etc/wifibroadcast.cfg") as f:
|
with open("/etc/wifibroadcast.cfg") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line.startswith("wifi_channel"):
|
if line.startswith("wifi_channel"):
|
||||||
# ex: "wifi_channel = 6 # commentaire"
|
|
||||||
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"
|
||||||
|
if new_label != _band_label:
|
||||||
|
print(f"[BAND] Changement détecté : {_band_label} -> {new_label}")
|
||||||
|
_band_label = new_label
|
||||||
|
break
|
||||||
except (FileNotFoundError, ValueError, IndexError) as e:
|
except (FileNotFoundError, ValueError, IndexError) as e:
|
||||||
print(f"[BAND] Impossible de lire wifi_channel : {e}")
|
print(f"[BAND] Impossible de lire wifi_channel : {e}")
|
||||||
return "?"
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user