From be75f73392ae6724dfda87565251e5348cef5787 Mon Sep 17 00:00:00 2001 From: Roby Date: Sun, 19 Apr 2026 09:06:01 +0200 Subject: [PATCH] Enanced Auto-healing --- agent/system_monitor.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/agent/system_monitor.py b/agent/system_monitor.py index 40a4629..4cd5b47 100644 --- a/agent/system_monitor.py +++ b/agent/system_monitor.py @@ -172,6 +172,33 @@ def check_auto_healing(client, status): msg = f"🛠 Auto-healing: {proc_name} offline. Restarting {attempts+1}/3..." client.publish(f"devices/{CLIENT_ID}/logs", msg) send_telegram_message(msg) + + # --- SPECIAL RULE FOR MMDVMHOST --- + # If the failed daemon is MMDVMHost, perform a hardware reset of the modem first + if proc_name.lower() == "mmdvmhost" and GPIO_AVAILABLE: + try: + RESET_PIN = 21 + GPIO.setwarnings(False) + GPIO.setmode(GPIO.BCM) + GPIO.setup(RESET_PIN, GPIO.OUT) + + # Send pulse + GPIO.output(RESET_PIN, GPIO.LOW) + time.sleep(0.5) + GPIO.output(RESET_PIN, GPIO.HIGH) + GPIO.cleanup(RESET_PIN) + + msg_hw = "🔌 Auto-healing: Hardware HAT Reset sent" + print(f"[{CLIENT_ID}] {msg_hw}") + client.publish(f"devices/{CLIENT_ID}/logs", msg_hw) + + # Wait for the modem firmware to boot before starting the daemon + time.sleep(1.5) + except Exception as e: + print(f"Auto-healing GPIO Error: {e}") + # ---------------------------------- + + # Restart the service (whether MMDVMHost or any other) subprocess.run(["sudo", "systemctl", "restart", proc_name]) elif attempts == 3: msg = f"🚨 CRITICAL: {proc_name} failed!" @@ -380,7 +407,7 @@ def on_message(client, userdata, msg): def auto_publish_task(client): while True: status = publish_all(client) - publish_all_ini_files(client) # <--- HERE IS THE CORRECT LOOP! + publish_all_ini_files(client) check_auto_healing(client, status) time.sleep(cfg['settings'].get('update_interval', 30))