12
12
#include " NimBLEDevice.h"
13
13
14
14
NimBLEScan* pBLEScan;
15
- uint32_t scanTime = 30 ; // Scan duration in seconds (0 = forever)
15
+ uint32_t scanTimeMs = 30 * 1000 ; // Scan duration in seconds (0 = forever)
16
16
17
17
// 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) {
20
20
Serial.printf (" Advertised Device: %s \n " , advertisedDevice->toString ().c_str ());
21
21
}
22
- };
22
+ } scanCallbacks ;
23
23
24
24
void setup () {
25
25
Serial.begin (115200 );
@@ -32,16 +32,16 @@ void setup() {
32
32
pBLEScan = NimBLEDevice::getScan ();
33
33
34
34
// Set the callback for when devices are discovered, no duplicates.
35
- pBLEScan->setAdvertisedDeviceCallbacks ( new MyAdvertisedDeviceCallbacks () , false );
35
+ pBLEScan->setScanCallbacks (&scanCallbacks , false );
36
36
37
37
// Set active scanning, this will get scan response data from the advertiser.
38
38
pBLEScan->setActiveScan (true );
39
39
40
40
// Set how often the scan occurs/switches channels; in milliseconds,
41
- pBLEScan->setInterval (97 );
41
+ pBLEScan->setInterval (100 );
42
42
43
43
// How long to scan during the interval; in milliseconds.
44
- pBLEScan->setWindow (37 );
44
+ pBLEScan->setWindow (100 );
45
45
46
46
// Do not store the scan results, use callback only.
47
47
pBLEScan->setMaxResults (0 );
@@ -51,7 +51,7 @@ void loop() {
51
51
// When the scan stops, restart it. This will cause duplicate devices to be reported again.
52
52
if (pBLEScan->isScanning () == false ) {
53
53
// 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 );
55
55
}
56
56
57
57
// Short delay to allow the stack to reset states.
0 commit comments