mirror of
				https://github.com/0xFEEDC0DE64/arduino-esp32.git
				synced 2025-11-03 23:51:39 +01:00 
			
		
		
		
	* Set IDF to v3.2 * Remove BLE submodule * Add BLE lib source * Update Camera example to support OV3660
		
			
				
	
	
		
			40 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
/*
 | 
						|
   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 <BLEDevice.h>
 | 
						|
#include <BLEUtils.h>
 | 
						|
#include <BLEScan.h>
 | 
						|
#include <BLEAdvertisedDevice.h>
 | 
						|
 | 
						|
int scanTime = 5; //In seconds
 | 
						|
BLEScan* pBLEScan;
 | 
						|
 | 
						|
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("");
 | 
						|
  pBLEScan = BLEDevice::getScan(); //create new scan
 | 
						|
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
 | 
						|
  pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
 | 
						|
  pBLEScan->setInterval(100);
 | 
						|
  pBLEScan->setWindow(99);  // less or equal setInterval value
 | 
						|
}
 | 
						|
 | 
						|
void loop() {
 | 
						|
  // put your main code here, to run repeatedly:
 | 
						|
  BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
 | 
						|
  Serial.print("Devices found: ");
 | 
						|
  Serial.println(foundDevices.getCount());
 | 
						|
  Serial.println("Scan done!");
 | 
						|
  pBLEScan->clearResults();   // delete results fromBLEScan buffer to release memory
 | 
						|
  delay(2000);
 | 
						|
} |