From 406fec1c0af443c3765f47b56edf414de5c394e2 Mon Sep 17 00:00:00 2001 From: doudar Date: Sun, 23 Apr 2023 19:51:01 -0500 Subject: [PATCH] Fixed OTA Updates --- CHANGELOG.md | 1 + include/SS2KLog.h | 2 +- src/BLE_Client.cpp | 2 +- src/HTTP_Server_Basic.cpp | 30 +++++++++++++++--------------- src/Main.cpp | 15 +++++++-------- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 219cc13c..a3bb8136 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Simplified Platform Packages to work better with newest version of PlatformIO. - Fixed broken images in wiki. - Valid files displayed on OTA page. +- Increased heap for more reliable OTA updates. ### Hardware - tweaks to echelon bike mount - Revised an old shifter cover for more options. diff --git a/include/SS2KLog.h b/include/SS2KLog.h index d35e2513..9ca0ea70 100644 --- a/include/SS2KLog.h +++ b/include/SS2KLog.h @@ -23,7 +23,7 @@ #define LOG_HANDLER_TAG "Log_Handler" #ifndef DEBUG_LOG_BUFFER_SIZE -#define DEBUG_LOG_BUFFER_SIZE 2000 +#define DEBUG_LOG_BUFFER_SIZE 600 #endif #ifndef DEBUG_FILE_CHARS_PER_LINE diff --git a/src/BLE_Client.cpp b/src/BLE_Client.cpp index abcc9c03..9bf82a58 100644 --- a/src/BLE_Client.cpp +++ b/src/BLE_Client.cpp @@ -733,7 +733,7 @@ void SpinBLEClient::checkBLEReconnect() { if (scan) { if (!NimBLEDevice::getScan()->isScanning()) { spinBLEClient.scanProcess(BLE_RECONNECT_SCAN_DURATION); - Serial.println("scan"); + //Serial.println("scan"); } } } diff --git a/src/HTTP_Server_Basic.cpp b/src/HTTP_Server_Basic.cpp index f38688ac..6f2ccb84 100644 --- a/src/HTTP_Server_Basic.cpp +++ b/src/HTTP_Server_Basic.cpp @@ -745,22 +745,22 @@ void HTTP_Server::FirmwareUpdate() { //////// Update Firmware ///////// SS2K_LOG(HTTP_SERVER_LOG_TAG, "Updating Firmware...Please Wait"); - if ((availableVer > currentVer) && (userConfig.getAutoUpdate())) { - t_httpUpdate_return ret = httpUpdate.update(client, userConfig.getFirmwareUpdateURL() + String(FW_BINFILE)); - switch (ret) { - case HTTP_UPDATE_FAILED: - SS2K_LOG(HTTP_SERVER_LOG_TAG, "HTTP_UPDATE_FAILED Error %d : %s", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str()); - break; - - case HTTP_UPDATE_NO_UPDATES: - SS2K_LOG(HTTP_SERVER_LOG_TAG, "HTTP_UPDATE_NO_UPDATES"); - break; - - case HTTP_UPDATE_OK: - SS2K_LOG(HTTP_SERVER_LOG_TAG, "HTTP_UPDATE_OK"); - break; + if (((availableVer > currentVer) || updateAnyway) && (userConfig.getAutoUpdate())) { + t_httpUpdate_return ret = httpUpdate.update(client, userConfig.getFirmwareUpdateURL() + String(FW_BINFILE)); + switch (ret) { + case HTTP_UPDATE_FAILED: + SS2K_LOG(HTTP_SERVER_LOG_TAG, "HTTP_UPDATE_FAILED Error %d : %s", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str()); + break; + + case HTTP_UPDATE_NO_UPDATES: + SS2K_LOG(HTTP_SERVER_LOG_TAG, "HTTP_UPDATE_NO_UPDATES"); + break; + + case HTTP_UPDATE_OK: + SS2K_LOG(HTTP_SERVER_LOG_TAG, "HTTP_UPDATE_OK"); + break; + } } - } } else { // don't update SS2K_LOG(HTTP_SERVER_LOG_TAG, " - Current Version: %s", FIRMWARE_VERSION); } diff --git a/src/Main.cpp b/src/Main.cpp index 42fc3cb0..8c3268cb 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -124,6 +124,12 @@ void setup() { userPWC.printFile(); userPWC.saveToLittleFS(); + // Check for firmware update. It's important that this stays before BLE & + // HTTP setup because otherwise they use too much traffic and the device + // fails to update which really sucks when it corrupts your settings. + startWifi(); + httpServer.FirmwareUpdate(); + pinMode(currentBoard.shiftUpPin, INPUT_PULLUP); // Push-Button with input Pullup pinMode(currentBoard.shiftDownPin, INPUT_PULLUP); // Push-Button with input Pullup pinMode(LED_PIN, OUTPUT); @@ -152,18 +158,11 @@ void setup() { digitalWrite(LED_PIN, HIGH); - startWifi(); - // Configure and Initialize Logger logHandler.addAppender(&webSocketAppender); logHandler.addAppender(&udpAppender); logHandler.initialize(); - // Check for firmware update. It's important that this stays before BLE & - // HTTP setup because otherwise they use too much traffic and the device - // fails to update which really sucks when it corrupts your settings. - - httpServer.FirmwareUpdate(); ss2k.startTasks(); httpServer.start(); @@ -202,7 +201,7 @@ void SS2K::maintenanceLoop(void *pvParameters) { } if ((millis() - intervalTimer) > 2003) { // add check here for when to restart WiFi - // maybe if in STA mode and 8.8.8.8 no ping return? + // maybe if in STA mode and 8.8.8.8 no ping return? // ss2k.restartWifi(); logHandler.writeLogs(); webSocketAppender.Loop();