Skip to content

Commit 8edf4c9

Browse files
BrentIOclaude
andcommitted
fix: defer HA-triggered OTA execOTA() out of MQTT callback to main loop
Calling execOTA() directly inside the MQTT message handler blocked while downloading firmware, causing MQTT to disconnect. Mirrors the forced-update pattern: set _otaNonForcedPendingRequest in the callback and execute from the main loop after MQTT processing is complete. Closes #686 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 43b27c6 commit 8edf4c9

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

Controller/Controller.ino

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ WiFiClientSecure _otaHttpsClient; /* TLS client used when the manifest URL
112112
String _otaManifestUrl; /* Set when setup_OtaFirmware() succeeds; empty otherwise */
113113
bool _otaUpdateInProcess = false;
114114
bool _otaPendingRequest = false;
115+
bool _otaNonForcedPendingRequest = false;
115116
bool _otaCheckFailed = false; /* Set by onError during checkForUpdate(); reset before each check */
116117
int _otaCheckErrorCode = 0; /* Error code captured by onError during checkForUpdate() */
117118
JsonDocument _otaPendingDoc;
@@ -976,6 +977,14 @@ void loop() {
976977

977978
otaFirmware_checkPending();
978979

980+
if(_otaNonForcedPendingRequest && !_otaUpdateInProcess){
981+
_otaNonForcedPendingRequest = false;
982+
_otaUpdateInProcess = true;
983+
_otaCurrentPartition[0] = '\0';
984+
otaFirmware.execOTA();
985+
_otaUpdateInProcess = false;
986+
}
987+
979988
oled.loop();
980989
authToken.loop();
981990
frontPanel.loop();
@@ -4375,7 +4384,7 @@ void eventHandler_mqttMessageReceived(char* topic, byte* pl, unsigned int length
43754384
mqttClient.publish(topic, buffer);
43764385

43774386
if(!_otaManifestUrl.isEmpty()){
4378-
otaFirmware.execOTA();
4387+
_otaNonForcedPendingRequest = true;
43794388
}
43804389
return;
43814390
}

0 commit comments

Comments
 (0)