Pause BMS reconnect after BLE scan
This commit is contained in:
@@ -18,6 +18,7 @@ static size_t responseLength = 0;
|
||||
static bool responseReady = false;
|
||||
|
||||
static unsigned long lastReadAttempt = 0;
|
||||
static unsigned long bmsReconnectPausedUntil = 0;
|
||||
static const unsigned long READ_INTERVAL_MS = 5000;
|
||||
|
||||
BmsData bmsData;
|
||||
@@ -67,6 +68,10 @@ static void handleNotify(
|
||||
}
|
||||
|
||||
|
||||
void pauseBmsReconnect(uint32_t pauseMs) {
|
||||
bmsReconnectPausedUntil = millis() + pauseMs;
|
||||
}
|
||||
|
||||
int getBleScanResultCount() {
|
||||
return bleScanResultCount;
|
||||
}
|
||||
@@ -81,6 +86,7 @@ const BleScanResult* getBleScanResult(int index) {
|
||||
|
||||
int scanBleDevices(uint32_t scanSeconds) {
|
||||
Serial.println("BLE: Starting scan...");
|
||||
pauseBmsReconnect((scanSeconds * 1000UL) + 30000UL);
|
||||
|
||||
if (client && client->isConnected()) {
|
||||
Serial.println("BLE: Disconnecting BMS before scan");
|
||||
@@ -337,6 +343,10 @@ void initBms() {
|
||||
}
|
||||
|
||||
void updateBms() {
|
||||
if ((long)(bmsReconnectPausedUntil - millis()) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (millis() - lastReadAttempt < READ_INTERVAL_MS) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -41,3 +41,4 @@ void updateBms();
|
||||
int scanBleDevices(uint32_t scanSeconds = 10);
|
||||
int getBleScanResultCount();
|
||||
const BleScanResult* getBleScanResult(int index);
|
||||
void pauseBmsReconnect(uint32_t pauseMs);
|
||||
|
||||
Reference in New Issue
Block a user