Pause BMS reconnect after BLE scan

This commit is contained in:
2026-06-04 02:11:12 -06:00
parent f29acd75ee
commit 038b142971
2 changed files with 11 additions and 0 deletions
+10
View File
@@ -18,6 +18,7 @@ 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 bmsReconnectPausedUntil = 0;
static const unsigned long READ_INTERVAL_MS = 5000; static const unsigned long READ_INTERVAL_MS = 5000;
BmsData bmsData; BmsData bmsData;
@@ -67,6 +68,10 @@ static void handleNotify(
} }
void pauseBmsReconnect(uint32_t pauseMs) {
bmsReconnectPausedUntil = millis() + pauseMs;
}
int getBleScanResultCount() { int getBleScanResultCount() {
return bleScanResultCount; return bleScanResultCount;
} }
@@ -81,6 +86,7 @@ const BleScanResult* getBleScanResult(int index) {
int scanBleDevices(uint32_t scanSeconds) { int scanBleDevices(uint32_t scanSeconds) {
Serial.println("BLE: Starting scan..."); Serial.println("BLE: Starting scan...");
pauseBmsReconnect((scanSeconds * 1000UL) + 30000UL);
if (client && client->isConnected()) { if (client && client->isConnected()) {
Serial.println("BLE: Disconnecting BMS before scan"); Serial.println("BLE: Disconnecting BMS before scan");
@@ -337,6 +343,10 @@ void initBms() {
} }
void updateBms() { void updateBms() {
if ((long)(bmsReconnectPausedUntil - millis()) > 0) {
return;
}
if (millis() - lastReadAttempt < READ_INTERVAL_MS) { if (millis() - lastReadAttempt < READ_INTERVAL_MS) {
return; return;
} }
+1
View File
@@ -41,3 +41,4 @@ void updateBms();
int scanBleDevices(uint32_t scanSeconds = 10); int scanBleDevices(uint32_t scanSeconds = 10);
int getBleScanResultCount(); int getBleScanResultCount();
const BleScanResult* getBleScanResult(int index); const BleScanResult* getBleScanResult(int index);
void pauseBmsReconnect(uint32_t pauseMs);