[SYS] Fix webUI OTA update free memory (#2103)

When doing an OTA update we deinit BT to free enough memory for the update

Co-authored-by: Florian <1technophile@users.noreply.github.com>
This commit is contained in:
FlorianandFlorian authored and GitHub committed 2024-11-11 17:27:26 -06:00
1 parent 87228b5f29
commit bb05011bdc
3 files changed
+15 -13

No files matched your search

+6 -2
View File
@@ -174,7 +174,8 @@ void BTConfig_fromJson(JsonObject& BTdata, bool startup = false) {
}
// Identify if the gateway is enabled or not and stop start accordingly
if (BTdata.containsKey("enabled") && BTdata["enabled"] == false && BTConfig.enabled == true) {
stopProcessing();
// Stop the gateway but without deinit to enable a future BT restart
stopProcessing(false);
} else if (BTdata.containsKey("enabled") && BTdata["enabled"] == true && BTConfig.enabled == false) {
BTProcessLock = false;
setupBTTasksAndBLE();
@@ -790,7 +791,7 @@ void BLEconnect() {
void BLEconnect() {}
# endif
void stopProcessing() {
void stopProcessing(bool deinit) {
if (BTConfig.enabled) {
BTProcessLock = true;
// We stop the scan
@@ -809,6 +810,9 @@ void stopProcessing() {
vTaskDelete(xProcBLETaskHandle);
xSemaphoreGive(semaphoreBLEOperation);
}
// Using deinit to free memory, should only be used if we are going to restart the gateway
if (deinit)
BLEDevice::deinit(true);
}
Log.notice(F("BLE gateway stopped, free heap: %d" CR), ESP.getFreeHeap());
}
+1 -1
View File
@@ -29,7 +29,7 @@
extern void setupBT();
extern void XtoBT(const char* topicOri, JsonObject& RFdata);
extern void launchBTDiscovery(bool overrideDiscovery);
extern void stopProcessing();
extern void stopProcessing(bool deinit);
extern String stateBTMeasures(bool);
#ifdef ESP32
+8 -10
View File
@@ -1662,7 +1662,7 @@ void setOTA() {
#ifdef ESP32
ProcessLock = true;
# ifdef ZgatewayBT
stopProcessing();
stopProcessing(true);
# endif
#endif
lpDisplayPrint("OTA in progress");
@@ -2455,7 +2455,7 @@ void sleep() {
# endif
Log.trace(F("Deactivating ESP32 components" CR));
# ifdef ZgatewayBT
stopProcessing();
stopProcessing(true);
ProcessLock = true;
# endif
# pragma GCC diagnostic push
@@ -3199,10 +3199,10 @@ void MQTTHttpsFWUpdate(const char* topicOri, JsonObject& HttpsFwUpdateData) {
# ifdef ESP32
ProcessLock = true;
# ifdef ZgatewayBT
stopProcessing();
stopProcessing(true);
# endif
# endif
Log.warning(F("Starting firmware update" CR));
Log.warning(F("Starting firmware update with %d freeHeap" CR), ESP.getFreeHeap());
gatewayState = GatewayState::REMOTE_OTA_IN_PROGRESS;
StaticJsonDocument<JSON_MSG_BUFFER> jsondata;
@@ -3244,11 +3244,9 @@ void MQTTHttpsFWUpdate(const char* topicOri, JsonObject& HttpsFwUpdateData) {
mqtt.reset();
mqttSetupPending = true;
update_client = *static_cast<WiFiClientSecure*>(eClient.get());
} else
# endif
{
TheengsUtils::syncNTP();
}
# endif
TheengsUtils::syncNTP();
# ifdef ESP32
update_client.setCACert(ota_cert.c_str());
@@ -3381,7 +3379,7 @@ void XtoSYS(const char* topicOri, JsonObject& SYSdata) { // json object decoding
#ifdef ESP32
ProcessLock = true;
# ifdef ZgatewayBT
stopProcessing();
stopProcessing(true);
# endif
#endif
String prev_ssid = WiFi.SSID();
@@ -3527,7 +3525,7 @@ void XtoSYS(const char* topicOri, JsonObject& SYSdata) { // json object decoding
# ifdef ESP32
ProcessLock = true;
# ifdef ZgatewayBT
stopProcessing();
stopProcessing(true);
# endif
# endif