Skip to content

Commit fe99b08

Browse files
committed
Add RAK3112 BLE Scanner example
1 parent 6c5b77d commit fe99b08

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
@file api-test.ino
3+
@author Bernd Giesecke ([email protected])
4+
@brief BLE Scanner example
5+
@version 0.1
6+
@date 2021-09-10
7+
8+
@copyright Copyright (c) 2021
9+
10+
*/
11+
12+
#include <Arduino.h>
13+
#include <BLEDevice.h>
14+
#include <BLEUtils.h>
15+
#include <BLEScan.h>
16+
#include <BLEAdvertisedDevice.h>
17+
18+
int scanTime = 5; // In seconds
19+
BLEScan *pBLEScan;
20+
BLEScanResults foundDevices;
21+
22+
class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks
23+
{
24+
void onResult(BLEAdvertisedDevice advertisedDevice)
25+
{
26+
Serial.printf("RSSI %d Name: %s\n", advertisedDevice.getRSSI(), advertisedDevice.getName().c_str());
27+
}
28+
};
29+
30+
void setup()
31+
{
32+
Serial.begin(115200);
33+
Serial.println("Scanning...");
34+
35+
BLEDevice::init("");
36+
pBLEScan = BLEDevice::getScan(); // create new scan
37+
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
38+
pBLEScan->setActiveScan(true); // active scan uses more power, but get results faster
39+
pBLEScan->setInterval(100);
40+
pBLEScan->setWindow(99); // less or equal setInterval value
41+
}
42+
43+
void loop()
44+
{
45+
// Start the scan
46+
pBLEScan->start(scanTime, false);
47+
48+
Serial.println("Scan done!");
49+
pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
50+
delay(2000);
51+
}

0 commit comments

Comments
 (0)