From 0c324857a574b26307788c09e08af1c0123671a8 Mon Sep 17 00:00:00 2001 From: kolban Date: Sun, 10 Sep 2017 13:42:22 -0500 Subject: 0.3.0 --- examples/BLE_scan/BLE_scan.ino | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/BLE_scan/BLE_scan.ino (limited to 'examples/BLE_scan') diff --git a/examples/BLE_scan/BLE_scan.ino b/examples/BLE_scan/BLE_scan.ino new file mode 100644 index 0000000..ef7d892 --- /dev/null +++ b/examples/BLE_scan/BLE_scan.ino @@ -0,0 +1,36 @@ +/* + Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp + Ported to Arduino ESP32 by Evandro Copercini +*/ + +#include +#include +#include +#include + +int scanTime = 30; //In seconds + +class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { + void onResult(BLEAdvertisedDevice advertisedDevice) { + Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str()); + } +}; + +void setup() { + Serial.begin(115200); + Serial.println("Scanning..."); + + BLEDevice::init(""); + BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan + pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); + pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster + BLEScanResults foundDevices = pBLEScan->start(scanTime); + Serial.print("Devices found: "); + Serial.println(foundDevices.getCount()); + Serial.println("Scan done!"); +} + +void loop() { + // put your main code here, to run repeatedly: + delay(2000); +} \ No newline at end of file -- cgit v1.2.3