Skip to content

Commit

Permalink
Update examples for NimBLE-Arduino 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
h2zero committed Dec 20, 2024
1 parent 3880c97 commit 8ff1543
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void setup() {
void loop() {
if (!pAdvertising->isAdvertising()) {
// Update the advertised data
pAdvertising->setServiceData(dataUuid, std::string((char*)&count, sizeof(count)));
pAdvertising->setServiceData(dataUuid, reinterpret_cast<uint8_t*>(&count), sizeof(count));

// Start advertising the data
pAdvertising->start(5);
Expand Down
16 changes: 8 additions & 8 deletions libraries/n-able/examples/BLE_Scan/BLE_Scan.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
#include "NimBLEDevice.h"

NimBLEScan* pBLEScan;
uint32_t scanTime = 30; // Scan duration in seconds (0 = forever)
uint32_t scanTimeMs = 30 * 1000; // Scan duration in seconds (0 = forever)

// Callback class for received advertisements
class MyAdvertisedDeviceCallbacks: public NimBLEAdvertisedDeviceCallbacks {
void onResult(NimBLEAdvertisedDevice* advertisedDevice) {
class ScanCallbacks: public NimBLEScanCallbacks {
void onResult(const NimBLEAdvertisedDevice* advertisedDevice) {
Serial.printf("Advertised Device: %s \n", advertisedDevice->toString().c_str());
}
};
} scanCallbacks;

void setup() {
Serial.begin(115200);
Expand All @@ -32,16 +32,16 @@ void setup() {
pBLEScan = NimBLEDevice::getScan();

// Set the callback for when devices are discovered, no duplicates.
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks(), false);
pBLEScan->setScanCallbacks(&scanCallbacks, false);

// Set active scanning, this will get scan response data from the advertiser.
pBLEScan->setActiveScan(true);

// Set how often the scan occurs/switches channels; in milliseconds,
pBLEScan->setInterval(97);
pBLEScan->setInterval(100);

// How long to scan during the interval; in milliseconds.
pBLEScan->setWindow(37);
pBLEScan->setWindow(100);

// Do not store the scan results, use callback only.
pBLEScan->setMaxResults(0);
Expand All @@ -51,7 +51,7 @@ void loop() {
// When the scan stops, restart it. This will cause duplicate devices to be reported again.
if(pBLEScan->isScanning() == false) {
// Start scan with: duration = scanTime (seconds), no scan ended callback, not a continuation of a previous scan.
pBLEScan->start(scanTime, nullptr, false);
pBLEScan->start(scanTimeMs);
}

// Short delay to allow the stack to reset states.
Expand Down

0 comments on commit 8ff1543

Please sign in to comment.