Skip to content

Commit 15b3dfe

Browse files
committed
Update examples for NimBLE-Arduino 2.x
1 parent 3880c97 commit 15b3dfe

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

libraries/n-able/examples/BLE_Advertiser/BLE_Advertiser.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void setup() {
3030
void loop() {
3131
if (!pAdvertising->isAdvertising()) {
3232
// Update the advertised data
33-
pAdvertising->setServiceData(dataUuid, std::string((char*)&count, sizeof(count)));
33+
pAdvertising->setServiceData(dataUuid, reinterpret_cast<uint8_t*>(&count), sizeof(count));
3434

3535
// Start advertising the data
3636
pAdvertising->start(5);
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'-DCONFIG_MAIN_TASK_STACK_SIZE=128'
22
'-DCONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE=1024'
3-
'-DCONFIG_BT_NIMBLE_ROLE_CENTRAL_DISABLED'
43
'-DCONFIG_BT_NIMBLE_ROLE_OBSERVER_DISABLED'
54
'-DCONFIG_BT_NIMBLE_ROLE_PERIPHERAL_DISABLED'

libraries/n-able/examples/BLE_Scan/BLE_Scan.ino

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
#include "NimBLEDevice.h"
1313

1414
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)
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

2424
void 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

Comments
 (0)