kolban

Untitled

Nov 9th, 2017
5,161
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. * Perform scanning for BLE advertised servers.
  3. */
  4. #include "BLEUtils.h"
  5. #include "BLEScan.h"
  6. #include <esp_log.h>
  7. #include <string>
  8.  
  9. #include "BLEDevice.h"
  10. #include "BLEAdvertisedDevice.h"
  11. #include "sdkconfig.h"
  12.  
  13. static const char LOG_TAG[] = "SampleScan";
  14.  
  15. class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
  16. void onResult(BLEAdvertisedDevice advertisedDevice) {
  17. ESP_LOGD(LOG_TAG, "Advertised Device: %s", advertisedDevice.toString().c_str());
  18. }
  19. };
  20.  
  21. static void run() {
  22. ESP_LOGD(LOG_TAG, "Scanning sample starting");
  23. BLEDevice::init("");
  24. BLEScan* pBLEScan = BLEDevice::getScan();
  25. pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  26. pBLEScan->setActiveScan(true);
  27. BLEScanResults scanResults = pBLEScan->start(10);
  28. ESP_LOGD(LOG_TAG, "We found %d devices", scanResults.getCount());
  29. scanResults.dump();
  30. ESP_LOGD(LOG_TAG, "Scanning sample ended");
  31. }
  32.  
  33. void SampleScan(void)
  34. {
  35. run();
  36. } // app_main
RAW Paste Data