1212#include " NimBLEDevice.h"
1313
1414NimBLEScan* pBLEScan;
15- uint32_t scanTime = 30 ; // Scan duration in seconds (0 = forever)
15+ uint32_t scanTimeMs = 30 * 1000 ; // Scan duration in seconds (0 = forever)
1616
1717// Callback class for received advertisements
18- class MyAdvertisedDeviceCallbacks : public NimBLEAdvertisedDeviceCallbacks {
19- void onResult (NimBLEAdvertisedDevice* advertisedDevice) {
18+ class ScanCallbacks : public NimBLEScanCallbacks {
19+ void onResult (const NimBLEAdvertisedDevice* advertisedDevice) {
2020 Serial.printf (" Advertised Device: %s \n " , advertisedDevice->toString ().c_str ());
2121 }
22- };
22+ } scanCallbacks ;
2323
2424void setup () {
2525 Serial.begin (115200 );
@@ -32,16 +32,16 @@ void setup() {
3232 pBLEScan = NimBLEDevice::getScan ();
3333
3434 // Set the callback for when devices are discovered, no duplicates.
35- pBLEScan->setAdvertisedDeviceCallbacks ( new MyAdvertisedDeviceCallbacks () , false );
35+ pBLEScan->setScanCallbacks (&scanCallbacks , false );
3636
3737 // Set active scanning, this will get scan response data from the advertiser.
3838 pBLEScan->setActiveScan (true );
3939
4040 // Set how often the scan occurs/switches channels; in milliseconds,
41- pBLEScan->setInterval (97 );
41+ pBLEScan->setInterval (100 );
4242
4343 // How long to scan during the interval; in milliseconds.
44- pBLEScan->setWindow (37 );
44+ pBLEScan->setWindow (100 );
4545
4646 // Do not store the scan results, use callback only.
4747 pBLEScan->setMaxResults (0 );
@@ -51,7 +51,7 @@ void loop() {
5151 // When the scan stops, restart it. This will cause duplicate devices to be reported again.
5252 if (pBLEScan->isScanning () == false ) {
5353 // Start scan with: duration = scanTime (seconds), no scan ended callback, not a continuation of a previous scan.
54- pBLEScan->start (scanTime, nullptr , false );
54+ pBLEScan->start (scanTimeMs );
5555 }
5656
5757 // Short delay to allow the stack to reset states.
0 commit comments