Advertisement
kolban

Untitled

Aug 7th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <BLE.h>
  2. #include <BLEUtils.h>
  3. #include <BLEScan.h>
  4. #include <BLEAdvertisedDevice.h>
  5. #include <esp_log.h>
  6.  
  7. class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
  8. void onResult(BLEAdvertisedDevice advertisedDevice) {
  9. Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
  10. }
  11. };
  12.  
  13. void setup() {
  14. esp_log_level_set("*", ESP_LOG_VERBOSE);
  15. Serial.begin(115200);
  16. Serial.println("Scanning...");
  17.  
  18. BLE::initClient();
  19. BLEScan* pBLEScan = BLE::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