forked from espressif/arduino-esp32
[2.0.0] BtClassic Discovery with info without connect (#4811)
Hey guys, so I wanted to do a BtClassic Discovery without the need to call connect and to list all found devices on a display and continue work with that list. I wasn't capable to test the example code with my file structure, but I did use the discovery already in some different situations. However when I noted that the Bluedroid stack won't let me enforce an RfComm SPP connection to a GPS Device (Skytraxx 2 plus, I guess its interface is built so simple that it doesn't advertise its SPP over SDP), I will probably have to switch to BtStack (BlueKitchen) and stop on this side meanwhile
This commit is contained in:
@ -0,0 +1,52 @@
|
||||
#include <BluetoothSerial.h>
|
||||
|
||||
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
|
||||
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
|
||||
#endif
|
||||
|
||||
BluetoothSerial SerialBT;
|
||||
|
||||
|
||||
#define BT_DISCOVER_TIME 10000
|
||||
|
||||
|
||||
static bool btScanAsync = true;
|
||||
static bool btScanSync = true;
|
||||
|
||||
|
||||
void btAdvertisedDeviceFound(BTAdvertisedDevice* pDevice) {
|
||||
Serial.printf("Found a device asynchronously: %s\n", pDevice->toString().c_str());
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
SerialBT.begin("ESP32test"); //Bluetooth device name
|
||||
Serial.println("The device started, now you can pair it with bluetooth!");
|
||||
|
||||
|
||||
if (btScanAsync) {
|
||||
Serial.print("Starting discoverAsync...");
|
||||
if (SerialBT.discoverAsync(btAdvertisedDeviceFound)) {
|
||||
Serial.println("Findings will be reported in \"btAdvertisedDeviceFound\"");
|
||||
delay(10000);
|
||||
Serial.print("Stopping discoverAsync... ");
|
||||
SerialBT.discoverAsyncStop();
|
||||
Serial.println("stopped");
|
||||
} else {
|
||||
Serial.println("Error on discoverAsync f.e. not workin after a \"connect\"");
|
||||
}
|
||||
}
|
||||
|
||||
if (btScanSync) {
|
||||
Serial.println("Starting discover...");
|
||||
BTScanResults *pResults = SerialBT.discover(BT_DISCOVER_TIME);
|
||||
if (pResults)
|
||||
pResults->dump(&Serial);
|
||||
else
|
||||
Serial.println("Error on BT Scan, no result!");
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(100);
|
||||
}
|
Reference in New Issue
Block a user