From 7da6471ff9dfe55bc1842f3f3da863854b2b1f09 Mon Sep 17 00:00:00 2001 From: Roby Date: Tue, 21 Apr 2026 14:32:56 +0200 Subject: [PATCH] Enanced auto-healing --- agent/system_monitor.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/agent/system_monitor.py b/agent/system_monitor.py index e3d89a0..3dffc13 100644 --- a/agent/system_monitor.py +++ b/agent/system_monitor.py @@ -182,6 +182,27 @@ def check_auto_healing(client, status): msg = f"🛠 Auto-healing: {proc_name} offline. Riavvio {attempts+1}/3..." client.publish(f"devices/{CLIENT_ID}/logs", msg) send_telegram_message(msg) + + # --- INIZIO MODIFICA: RESET HARDWARE SPECIFICO PER MMDVMHOST --- + if proc_name.lower() == "mmdvmhost" and GPIO_AVAILABLE: + logger.info("Esecuzione RESET HAT automatico pre-riavvio MMDVMHost...") + try: + RESET_PIN = 21 # Assicurati che il PIN sia quello corretto per i tuoi nodi + GPIO.setwarnings(False) + GPIO.setmode(GPIO.BCM) + GPIO.setup(RESET_PIN, GPIO.OUT) + # Impulso LOW per resettare + GPIO.output(RESET_PIN, GPIO.LOW) + time.sleep(0.5) + GPIO.output(RESET_PIN, GPIO.HIGH) + GPIO.cleanup(RESET_PIN) + # Diamo tempo al microcontrollore di riavviarsi + time.sleep(1.5) + client.publish(f"devices/{CLIENT_ID}/logs", "🔌 Impulso GPIO (Reset MMDVM) inviato!") + except Exception as e: + logger.error(f"Errore GPIO in auto-healing: {e}") + # --- FINE MODIFICA --- + subprocess.run(["sudo", "systemctl", "restart", proc_name]) elif attempts == 3: msg = f"🚨 CRITICO: {proc_name} fallito!"