From cb926a42333ee456ff4e5e6755227240c5533688 Mon Sep 17 00:00:00 2001 From: nick Date: Thu, 4 Jun 2026 17:16:45 -0600 Subject: [PATCH] Revert "Add BMS reconnect backoff" This reverts commit fa96a327a67e17b39cc7121635a24dd117b48dc3. Changes to be committed: modified: firmware/esp32/overland-controller/bms.cpp --- firmware/esp32/overland-controller/bms.cpp | 77 ++++++---------------- 1 file changed, 21 insertions(+), 56 deletions(-) diff --git a/firmware/esp32/overland-controller/bms.cpp b/firmware/esp32/overland-controller/bms.cpp index 86fdda1..cb21d14 100644 --- a/firmware/esp32/overland-controller/bms.cpp +++ b/firmware/esp32/overland-controller/bms.cpp @@ -14,14 +14,6 @@ static NimBLEClient* client = nullptr; static NimBLERemoteCharacteristic* notifyChar = nullptr; static NimBLERemoteCharacteristic* writeChar = nullptr; -static unsigned long lastBmsAttemptMs = 0; -static unsigned long bmsRetryIntervalMs = 30000; -static const unsigned long BMS_RETRY_INTERVAL_CONNECTED_MS = 5000; -static const unsigned long BMS_RETRY_INTERVAL_FAILED_MS = 30000; -static const unsigned long BMS_RETRY_INTERVAL_LONG_FAIL_MS = 60000; -static int consecutiveBmsFailures = 0; - - static uint8_t responseBuffer[128]; static size_t responseLength = 0; static bool responseReady = false; @@ -511,58 +503,31 @@ void initBms() { } void updateBms() { - if (!appConfig.bms.enabled || appConfig.bms.address.length() == 0) { - bmsData.connected = false; + if (bmsSetupMode) { return; } - unsigned long now = millis(); - - if (!client || !client->isConnected()) { - bmsData.connected = false; - - if (now - lastBmsAttemptMs < bmsRetryIntervalMs) { - return; - } - - lastBmsAttemptMs = now; - - if (!connectBms()) { - consecutiveBmsFailures++; - - if (consecutiveBmsFailures >= 3) { - bmsRetryIntervalMs = BMS_RETRY_INTERVAL_LONG_FAIL_MS; - } else { - bmsRetryIntervalMs = BMS_RETRY_INTERVAL_FAILED_MS; - } - - return; - } - - consecutiveBmsFailures = 0; - bmsRetryIntervalMs = BMS_RETRY_INTERVAL_CONNECTED_MS; - } - - if (!requestBmsData()) { - bmsData.connected = false; - consecutiveBmsFailures++; - - if (client) { - client->disconnect(); - } - - if (consecutiveBmsFailures >= 3) { - bmsRetryIntervalMs = BMS_RETRY_INTERVAL_LONG_FAIL_MS; - } else { - bmsRetryIntervalMs = BMS_RETRY_INTERVAL_FAILED_MS; - } - - lastBmsAttemptMs = now; + if ((long)(bmsReconnectPausedUntil - millis()) > 0) { return; } - consecutiveBmsFailures = 0; - bmsRetryIntervalMs = BMS_RETRY_INTERVAL_CONNECTED_MS; - bmsData.connected = true; + if (millis() - lastReadAttempt < READ_INTERVAL_MS) { + return; + } + + lastReadAttempt = millis(); + + if (!connectBms()) { + return; + } + + if (requestPacket(JBD_STATUS_REQUEST, sizeof(JBD_STATUS_REQUEST))) { + parseBasicInfo(); + } + + delay(100); + + if (requestPacket(JBD_CELL_REQUEST, sizeof(JBD_CELL_REQUEST))) { + parseCellVoltages(); + } } -