BLE Scanner Device Found 0

Please help me, I have try BLE Scan but when I call the MyAdvertisedDeviceCallbacks class the device found result is 0 but when I am not calling the class the device found show the result is 2. is there any wrong with my code? I am using ESP32 Dev Kit V1

Here is my code:

<pre class="brush: lang">

/*
   Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp
   Ported to Arduino ESP32 by Evandro Copercini
*/

#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);
}

</pre>

And here is the Result:

<pre class="brush: lang">

Advertised Device: Name: honor Band 3-f15, Address: 34:12:f9:03:1f:15, appearance: 0, manufacturer data: 7d02010300ffcc, serviceUUID: 00001812-0000-1000-8000-00805f9b34fb, txPower: 4 
Advertised Device: Name: honor Band 3-f15, Address: 34:12:f9:03:1f:15, appearance: 0, manufacturer data: 7d02010300ffcc, serviceUUID: 00001812-0000-1000-8000-00805f9b34fb, txPower: 4 
Advertised Device: Name: Charge HR, Address: f5:02:71:f9:46:a7, serviceUUID: adabfb00-6e7d-4601-bda2-bffaa68956ba, txPower: -6 
Advertised Device: Name: honor Band 3-f15, Address: 34:12:f9:03:1f:15, appearance: 0, manufacturer data: 7d02010300ffcc, serviceUUID: 00001812-0000-1000-8000-00805f9b34fb, txPower: 4 
Advertised Device: Name: honor Band 3-f15, Address: 34:12:f9:03:1f:15, appearance: 0, manufacturer data: 7d02010300ffcc, serviceUUID: 00001812-0000-1000-8000-00805f9b34fb, txPower: 4 
Devices found: 0
Scan done!

</pre>

 

Same problem here. I suppose at least you are also talking about:

pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());

With this line intact I get:

...

Advertised Device: Name: , Address: 64:62:10:f2:07:f3, manufacturer data: 4c0010054b1c8f619b
Devices found: 0
Scan done!

With the line commented out I get

Devices found: 17
Scan done!

 

 

  Joined March 29, 2021      1
Monday at 03:48 PM

What is the version of yours ESP32 Arduino code?

  Joined February 12, 2018      696
Monday at 02:11 PM