Back off BMS reconnect attempts
This commit is contained in:
@@ -19,6 +19,10 @@ static size_t responseLength = 0;
|
|||||||
static bool responseReady = false;
|
static bool responseReady = false;
|
||||||
|
|
||||||
static unsigned long lastReadAttempt = 0;
|
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 unsigned long bmsReconnectPausedUntil = 0;
|
||||||
static bool bmsSetupMode = false;
|
static bool bmsSetupMode = false;
|
||||||
static const unsigned long READ_INTERVAL_MS = 5000;
|
static const unsigned long READ_INTERVAL_MS = 5000;
|
||||||
@@ -517,8 +521,31 @@ void updateBms() {
|
|||||||
|
|
||||||
lastReadAttempt = millis();
|
lastReadAttempt = millis();
|
||||||
|
|
||||||
if (!connectBms()) {
|
if (!client || !client->isConnected()) {
|
||||||
return;
|
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))) {
|
if (requestPacket(JBD_STATUS_REQUEST, sizeof(JBD_STATUS_REQUEST))) {
|
||||||
|
|||||||
Reference in New Issue
Block a user