Hi there! I'm using the example "BLE_scan" for ESP32 BLE Arduino on my Sparkfun Thing Plus. The code works and on the serial monitor I see at least two distinct BLE-devices (see below snippet of serial monitor). However, it seems that the function "foundDevices.getCount()" which is executed after each scan always returns 0 devices? Am I missing something? Is this a bug?
Best regards, Baelor
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
int scanTime = 5; //In seconds
BLEScan* pBLEScan;
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
}
};
void setup() {
Serial.begin(115200);
Serial.println("Scanning...");
BLEDevice::init("");
pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
pBLEScan->setInterval(100);
pBLEScan->setWindow(99); // less or equal setInterval value
}
void loop() {
// put your main code here, to run repeatedly:
BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
Serial.print("Devices found: ");
Serial.println(foundDevices.getCount());
Serial.println("Scan done!");
pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
delay(2000);
}
00:42:31.889 -> Advertised Device: Name: Ruuvi BB43, Address: c5:cf:10:5c:a8:7b, manufacturer data: 99040fffffffffffffffffffffffffffffffffffff, serviceUUID: 6e400001-b5a3-f393-e0a9-e50e24dcca9e
00:42:31.889 -> Advertised Device: Name: , Address: 5c:a3:d3:28:ed:7e, serviceUUID: 0000fd6f-0000-1000-8000-00805f9b34fb
00:42:33.049 -> Devices found: 0
00:42:33.049 -> Scan done!