Reduce blocking BMS connection timeout
This commit is contained in:
@@ -21,7 +21,7 @@ static bool responseReady = false;
|
|||||||
static unsigned long lastReadAttempt = 0;
|
static unsigned long lastReadAttempt = 0;
|
||||||
|
|
||||||
static unsigned long lastBmsConnectAttempt = 0;
|
static unsigned long lastBmsConnectAttempt = 0;
|
||||||
static unsigned long bmsConnectBackoffMs = 30000;
|
static unsigned long bmsConnectBackoffMs = 120000;
|
||||||
static int bmsConnectFailCount = 0;
|
static int bmsConnectFailCount = 0;
|
||||||
static unsigned long bmsReconnectPausedUntil = 0;
|
static unsigned long bmsReconnectPausedUntil = 0;
|
||||||
static bool bmsSetupMode = false;
|
static bool bmsSetupMode = false;
|
||||||
@@ -317,6 +317,9 @@ static bool connectBms() {
|
|||||||
|
|
||||||
client = NimBLEDevice::createClient();
|
client = NimBLEDevice::createClient();
|
||||||
|
|
||||||
|
// Keep failed/out-of-range BMS attempts from freezing the web UI too long.
|
||||||
|
client->setConnectTimeout(3);
|
||||||
|
|
||||||
if (!client->connect(address)) {
|
if (!client->connect(address)) {
|
||||||
Serial.println("BMS: Connect failed");
|
Serial.println("BMS: Connect failed");
|
||||||
bmsData.connected = false;
|
bmsData.connected = false;
|
||||||
@@ -536,16 +539,16 @@ void updateBms() {
|
|||||||
bmsConnectFailCount++;
|
bmsConnectFailCount++;
|
||||||
|
|
||||||
if (bmsConnectFailCount >= 3) {
|
if (bmsConnectFailCount >= 3) {
|
||||||
bmsConnectBackoffMs = 60000;
|
bmsConnectBackoffMs = 120000;
|
||||||
} else {
|
} else {
|
||||||
bmsConnectBackoffMs = 30000;
|
bmsConnectBackoffMs = 60000;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bmsConnectFailCount = 0;
|
bmsConnectFailCount = 0;
|
||||||
bmsConnectBackoffMs = 30000;
|
bmsConnectBackoffMs = 60000;
|
||||||
}
|
}
|
||||||
|
|
||||||
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