From 8f2481025fae498cccff442fcf8acfe7ff5a3a51 Mon Sep 17 00:00:00 2001 From: nick Date: Thu, 4 Jun 2026 17:20:30 -0600 Subject: [PATCH] Back off BMS reconnect attempts --- firmware/esp32/overland-controller/bms.cpp | 31 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/firmware/esp32/overland-controller/bms.cpp b/firmware/esp32/overland-controller/bms.cpp index cb21d14..5b0ddec 100644 --- a/firmware/esp32/overland-controller/bms.cpp +++ b/firmware/esp32/overland-controller/bms.cpp @@ -19,6 +19,10 @@ static size_t responseLength = 0; static bool responseReady = false; static unsigned long lastReadAttempt = 0; + +static unsigned long lastBmsConnectAttempt = 0; +static unsigned long bmsConnectBackoffMs = 30000; +static int bmsConnectFailCount = 0; static unsigned long bmsReconnectPausedUntil = 0; static bool bmsSetupMode = false; static const unsigned long READ_INTERVAL_MS = 5000; @@ -517,8 +521,31 @@ void updateBms() { lastReadAttempt = millis(); - if (!connectBms()) { - return; + if (!client || !client->isConnected()) { + unsigned long now = millis(); + + if (now - lastBmsConnectAttempt < bmsConnectBackoffMs) { + bmsData.connected = false; + return; + } + + lastBmsConnectAttempt = now; + + if (!connectBms()) { + bmsData.connected = false; + bmsConnectFailCount++; + + if (bmsConnectFailCount >= 3) { + bmsConnectBackoffMs = 60000; + } else { + bmsConnectBackoffMs = 30000; + } + + return; + } + + bmsConnectFailCount = 0; + bmsConnectBackoffMs = 30000; } if (requestPacket(JBD_STATUS_REQUEST, sizeof(JBD_STATUS_REQUEST))) {