diff options
author | kolban <kolban1@kolban.com> | 2017-09-10 13:36:10 -0500 |
---|---|---|
committer | kolban <kolban1@kolban.com> | 2017-09-10 13:36:10 -0500 |
commit | 5e5b5b78f0aeca611edb52ff4e885334b6fe46a9 (patch) | |
tree | 8d207806891e66ee6ea292d82eb7f120e2138418 /ESP32_BLE_Arduino/examples/Arduino/BLE_scan/BLE_scan.ino | |
download | thermostat-5e5b5b78f0aeca611edb52ff4e885334b6fe46a9.tar.gz thermostat-5e5b5b78f0aeca611edb52ff4e885334b6fe46a9.tar.bz2 thermostat-5e5b5b78f0aeca611edb52ff4e885334b6fe46a9.zip |
0.1.0 release
Diffstat (limited to 'ESP32_BLE_Arduino/examples/Arduino/BLE_scan/BLE_scan.ino')
-rw-r--r-- | ESP32_BLE_Arduino/examples/Arduino/BLE_scan/BLE_scan.ino | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/ESP32_BLE_Arduino/examples/Arduino/BLE_scan/BLE_scan.ino b/ESP32_BLE_Arduino/examples/Arduino/BLE_scan/BLE_scan.ino new file mode 100644 index 0000000..ef7d892 --- /dev/null +++ b/ESP32_BLE_Arduino/examples/Arduino/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 <BLEDevice.h> +#include <BLEUtils.h> +#include <BLEScan.h> +#include <BLEAdvertisedDevice.h> + +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 |