-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
97 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
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 "Ble.h" | ||
#include <Arduino.h> | ||
|
||
int scanTime = 5; //In seconds | ||
|
||
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { | ||
void onResult(BLEAdvertisedDevice advertisedDevice) { | ||
Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str()); | ||
} | ||
}; | ||
|
||
void Ble::init() { | ||
// Serial.begin(115200); | ||
BLEDevice::init(""); | ||
} | ||
|
||
void Ble::scan() { | ||
Serial.println("Scanning..."); | ||
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!"); | ||
} | ||
|
||
Ble::Ble() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <BLEDevice.h> | ||
#include <BLEUtils.h> | ||
#include <BLEScan.h> | ||
#include <BLEAdvertisedDevice.h> | ||
|
||
class Ble { | ||
|
||
public: | ||
Ble(); | ||
void init(); | ||
void scan(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters