summaryrefslogtreecommitdiff
path: root/sensor/patchedBLE/examples/BLE_scan/BLE_scan.ino
blob: ef7d89246a93170dc6f31dc293b49d4277a6b923 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 MyAdvertisedDeviceCallbackspublic 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);
}