Classic bluetooth discovery

Mesrop
Posts: 1
Joined: Wed Nov 24, 2021 7:03 pm

Re: Classic bluetooth discovery

Postby Mesrop » Wed Nov 24, 2021 7:12 pm

Here is a solution

Code: Select all

#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);
}

CJKnero
Posts: 1
Joined: Mon Jan 03, 2022 1:57 pm

Re: Classic bluetooth discovery

Postby CJKnero » Mon Jan 03, 2022 2:19 pm

@andreas.liebenberg
I doubt that this is actually possible as the devices have to respond to an inquiry and if they don't choose to respond, no data is getting sent (I could be entirely wrong here). I am convinced that this behavior can be tweaked in the phone's settings because I believe to have seen a setting called 'turn on bluetooth discovery' in an android phone.
I would also kindly ask you to release your sketch (or part of it) in which you scan for classic BT devices using the 'esp_bt_gap_start_discovery' command (if you still have it). I have seen a few Github threads in which people couldn't find out a way to scan for these devices and I would also need it for a current project of mine as I'm struggling with it myself.

Thanks

Who is online

Users browsing this forum: No registered users and 73 guests