Advertisement
kolban

Untitled

Aug 16th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <BLEDevice.h>
  2. #include <BLEUtils.h>
  3. #include <BLEScan.h>
  4. #include <BLEAdvertisedDevice.h>
  5.  
  6. class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
  7. void onResult(BLEAdvertisedDevice advertisedDevice) {
  8. Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
  9. }
  10. };
  11.  
  12. void setup() {
  13.  
  14. Serial.begin(115200);
  15. Serial.println("Scanning...");
  16.  
  17. BLEDevice::init("");
  18. delay(200);
  19. BLEScan* pBLEScan = BLEDevice::getScan(); //create new scan
  20. pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  21. pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
  22. BLEScanResults foundDevices = pBLEScan->start(30); //scan for 30 seconds
  23. Serial.print("Devices found: ");
  24. Serial.println(foundDevices.getCount());
  25. Serial.println("Scan done!");
  26. }
  27.  
  28. void loop() {
  29. // put your main code here, to run repeatedly:
  30. delay(2000);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement