Back off BMS reconnect attempts
This commit is contained in:
@@ -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))) {
|
||||
|
||||
Reference in New Issue
Block a user