Use blocking BLE scan callback timing
This commit is contained in:
@@ -139,7 +139,7 @@ const BleScanResult* getBleScanResult(int index) {
|
||||
int scanBleDevices(uint32_t scanSeconds) {
|
||||
Serial.print(logTimestamp());
|
||||
Serial.println(" BLE: Starting scan...");
|
||||
pauseBmsReconnect((scanSeconds * 1000UL) + 30000UL);
|
||||
pauseBmsReconnect(60000UL);
|
||||
|
||||
if (client && client->isConnected()) {
|
||||
Serial.print(logTimestamp());
|
||||
@@ -162,11 +162,20 @@ int scanBleDevices(uint32_t scanSeconds) {
|
||||
scan->clearResults();
|
||||
|
||||
Serial.print(logTimestamp());
|
||||
Serial.print(" BLE: Scanning for ");
|
||||
Serial.print(" BLE: Blocking scan requested for ");
|
||||
Serial.print(scanSeconds);
|
||||
Serial.println(" seconds...");
|
||||
|
||||
bool started = scan->start(scanSeconds, false, false);
|
||||
unsigned long scanStart = millis();
|
||||
|
||||
bool started = scan->start(scanSeconds, false, true);
|
||||
|
||||
unsigned long scanElapsed = (millis() - scanStart) / 1000;
|
||||
|
||||
Serial.print(logTimestamp());
|
||||
Serial.print(" BLE: scan call returned after ");
|
||||
Serial.print(scanElapsed);
|
||||
Serial.println(" seconds");
|
||||
|
||||
if (!started) {
|
||||
Serial.print(logTimestamp());
|
||||
@@ -174,28 +183,6 @@ int scanBleDevices(uint32_t scanSeconds) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long startMs = millis();
|
||||
unsigned long durationMs = scanSeconds * 1000UL;
|
||||
unsigned long lastProgressMs = 0;
|
||||
|
||||
while (millis() - startMs < durationMs) {
|
||||
unsigned long elapsed = millis() - startMs;
|
||||
|
||||
if (elapsed - lastProgressMs >= 1000) {
|
||||
lastProgressMs = elapsed;
|
||||
|
||||
Serial.print(logTimestamp());
|
||||
Serial.print(" BLE: scanning... ");
|
||||
Serial.print(elapsed / 1000);
|
||||
Serial.print("/");
|
||||
Serial.print(scanSeconds);
|
||||
Serial.print(" sec, devices ");
|
||||
Serial.println(bleScanResultCount);
|
||||
}
|
||||
|
||||
delay(50);
|
||||
}
|
||||
|
||||
scan->stop();
|
||||
scan->clearResults();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user