Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYS] Fix webUI OTA update free memory #2103

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions main/ZgatewayBT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -790,7 +791,7 @@ void BLEconnect() {
void BLEconnect() {}
# endif

void stopProcessing() {
void stopProcessing(bool deinit) {
if (BTConfig.enabled) {
BTProcessLock = true;
// We stop the scan
Expand All @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion main/config_BT.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 8 additions & 10 deletions main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,7 @@ void setOTA() {
#ifdef ESP32
ProcessLock = true;
# ifdef ZgatewayBT
stopProcessing();
stopProcessing(true);
# endif
#endif
lpDisplayPrint("OTA in progress");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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

Expand Down