Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <BLEDevice.h>
- #include <BLEUtils.h>
- #include <BLEScan.h>
- #include <BLEAdvertisedDevice.h>
- 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("");
- delay(200);
- 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(30); //scan for 30 seconds
- Serial.print("Devices found: ");
- Serial.println(foundDevices.getCount());
- Serial.println("Scan done!");
- }
- void loop() {
- // put your main code here, to run repeatedly:
- delay(2000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement