From 050a4cdc5d013c99c7132b061ba9993a400fa19c Mon Sep 17 00:00:00 2001 From: XupaMisto Date: Wed, 27 May 2026 21:10:50 +0100 Subject: [PATCH] fix: loopOnce CPU fix + SWITCH_PRIMARY race condition fix --- api/listener_recovery.php | 8 +++----- api/mqtt_listener.php | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/api/listener_recovery.php b/api/listener_recovery.php index 511f252..763286d 100644 --- a/api/listener_recovery.php +++ b/api/listener_recovery.php @@ -592,10 +592,11 @@ while (true) { ); $nextMainCheck = time() + 10; + $loopStartedAt = microtime(true); while ($mqtt->isConnected()) { - $mqtt->loop(false); + $mqtt->loopOnce($loopStartedAt, true, 100000); if (time() >= $nextMainCheck) { @@ -617,9 +618,7 @@ while (true) { "MAIN broker online" ); - logmsg( - "Mandar switch_primary" - ); + logmsg("Mandar switch_primary"); send_switch_primary( $mqtt, @@ -635,7 +634,6 @@ while (true) { } } - usleep(100000); } $mqtt->disconnect(); diff --git a/api/mqtt_listener.php b/api/mqtt_listener.php index a0bc6d9..5e33ae6 100644 --- a/api/mqtt_listener.php +++ b/api/mqtt_listener.php @@ -188,10 +188,11 @@ while (true) { logmsg("TLS ligado"); $nextOfflineCheck = time() + 15; + $loopStartedAt = microtime(true); while ($mqttTls->isConnected()) { - $mqttTls->loop(true, false); + $mqttTls->loopOnce($loopStartedAt, true, 100000); if (time() >= $nextOfflineCheck) { $nextOfflineCheck = time() + 15; @@ -208,7 +209,6 @@ while (true) { } } - usleep(100000); } $mqttTls->disconnect();