fix: loopOnce CPU fix + SWITCH_PRIMARY race condition fix

This commit is contained in:
XupaMisto 2026-05-27 21:10:50 +01:00
parent e95740ec8c
commit 050a4cdc5d
2 changed files with 5 additions and 7 deletions

View File

@ -592,10 +592,11 @@ while (true) {
); );
$nextMainCheck = time() + 10; $nextMainCheck = time() + 10;
$loopStartedAt = microtime(true);
while ($mqtt->isConnected()) { while ($mqtt->isConnected()) {
$mqtt->loop(false); $mqtt->loopOnce($loopStartedAt, true, 100000);
if (time() >= $nextMainCheck) { if (time() >= $nextMainCheck) {
@ -617,9 +618,7 @@ while (true) {
"MAIN broker online" "MAIN broker online"
); );
logmsg( logmsg("Mandar switch_primary");
"Mandar switch_primary"
);
send_switch_primary( send_switch_primary(
$mqtt, $mqtt,
@ -635,7 +634,6 @@ while (true) {
} }
} }
usleep(100000);
} }
$mqtt->disconnect(); $mqtt->disconnect();

View File

@ -188,10 +188,11 @@ while (true) {
logmsg("TLS ligado"); logmsg("TLS ligado");
$nextOfflineCheck = time() + 15; $nextOfflineCheck = time() + 15;
$loopStartedAt = microtime(true);
while ($mqttTls->isConnected()) { while ($mqttTls->isConnected()) {
$mqttTls->loop(true, false); $mqttTls->loopOnce($loopStartedAt, true, 100000);
if (time() >= $nextOfflineCheck) { if (time() >= $nextOfflineCheck) {
$nextOfflineCheck = time() + 15; $nextOfflineCheck = time() + 15;
@ -208,7 +209,6 @@ while (true) {
} }
} }
usleep(100000);
} }
$mqttTls->disconnect(); $mqttTls->disconnect();