Back off BMS reconnect attempts

This commit is contained in:
2026-06-04 17:20:30 -06:00
parent cb926a4233
commit 8f2481025f
+28 -1
View File
@@ -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,10 +521,33 @@ void updateBms() {
lastReadAttempt = millis();
if (!connectBms()) {
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))) {
parseBasicInfo();
}