Bluetooth classic and BLE in ESP32 wroom

Hi
We are using ESP 32 wroom for our application .we want two ESP communication with each other through bluetooth.
is it possible to work with bluetooth classic . if poosible can you please send us how we are able to do
scanning and advertising in bluetooth classic.
we also tried with BLE examples as a central and server that are provided in arduino IDE .
but with BLE also they are not connected to each other but with serial bluetooth terminal it connect to mobile bluetooth.
here client search advertised devices and print to serial terminal but it not able to connect its not able to match service UUID so can you please share examples on BLE or suggestions on what we are missing with BLE.

Thanks.

If you want two ESP32s to talk to each other you want to use ESP-NOW.
Here is a good article on 2-way ESP-NOW:
ESP-NOW Two-Way Communication Between ESP8266 NodeMCU Boards | Random Nerd Tutorials

Hello
thanks for your suggestions to use ESP-NOW.
as per our application we only want to use BLE or bluetooth classic.

Which would you prefer to use? What are you going to send between the two modules?

we also tried with BLE examples as a central and server that are provided in arduino IDE .

Why could you not make the two BLE library example sketches for client and server work together. Be as detailed as possible.

The SerialBluetooth.h library is used for classic Bluetooth with the ESP32.
The two library examples for having one ESP32 connect to another is SerialToSerialBT and SerialToSerialBTM. The BTM sketch is for the master and it will connect to the other esp32.

hello
We just want it like to send a string between two Esp32 . whether is it a bluetooth classic or BLE .
our Application is like one ESP as a client and another is server .
I have used BLE library examples sketches for client and server together .
BLE server prints this message on serial terminal "Characteristic defined! Now you can read it in your phone! "
and at client it lists all BLE advertised devices near me and i think it stuck at
if (advertisedDevice.haveServiceUUID() && advertisedDevice.isAdvertisingService(serviceUUID))
this loop.
as per your suggestions SerialToSerialBT and SerialToSerialBTM i have tried with it but it showing me on serial terminal that "failed to connect .make sure remote device is available and in range ,then restart app" . but my both devices are in my table itself not having 1ft of distance between them.
Thanks.

"Failed to connect. Make sure remote device is available and in range, then restart app."

That line appears in the BTM sketch. If you use a Serial Bluetooth Terminal App like the one from Kai Morich can you connect with the device running the BT sketch at that point?

at client it lists all BLE advertised devices near me and i think it stuck at
if (advertisedDevice.haveServiceUUID() && advertisedDevice.isAdvertisingService(serviceUUID))
this loop.
as per your suggestions SerialToSerialBT and SerialToSerialBTM i have tried with it but it showing me on serial terminal that "failed to connect .

In both cases, the device which should connect to the other fails to connect. If you switch the two esp's around so they are each running the other code, does the problem persist in the same fashion, i.e. the device which is supposed to connect fails to connect?

yes the problem persist in same fashion .device failed to connect.
at BTM i got this message "Failed to connect. Make sure remote device is available and in range, then restart app."
I also tried with SerialToSerialBT_SSP_pairing_server if it waits for the pairing but it not working.
is there any changes required while working with BLE library example sketches for client and server ?

You did not answer the question about the phone app being able to connect with the slave.

yes with phone app i am able to connect

Good. That means the slave module is working correctly.

I am currently running these simplified paired sketches on two ESP32s. Upload into two instances of the IDE so that you can have two monitor windows open at the same time. My modules have a red/green led which I use as connection indicators. Modify as necessary to suit your modules. The slave sketch should be running before the master.

Slave Sketch


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

void setup() {
  Serial.begin(115200);
  pinMode(16, OUTPUT); //red dual color led
  pinMode(17, OUTPUT); //green dual color led
  SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair/connect it with phone!");
}

void loop() {
  if (Serial.available()) {
    SerialBT.write(Serial.read());
  }
  if (SerialBT.available()) {
    Serial.write(SerialBT.read());
    //SerialBT.write(SerialBT.read());//echo back
  }
  delay(20);

  if (SerialBT.connected())
  {
    digitalWrite(17, LOW);//turn on
    digitalWrite(16, HIGH);//turn off
  }
  else
  {
    digitalWrite(17, HIGH);//turn off
    digitalWrite(16, LOW); //turn on
  }

}

Master sketch


#include "BluetoothSerial.h"

BluetoothSerial SerialBT;

String name = "ESP32test";//device to connect with
bool connected;

void setup() {
  Serial.begin(115200);
  pinMode(16, OUTPUT); //red dual color led
  pinMode(17, OUTPUT); //green dual color led
  SerialBT.begin("ESP32test_Master", true); //true starts as master
  Serial.println("The device started in master mode, make sure remote BT device is on!");

  connected = SerialBT.connect(name);//connect to "ESP32test"

  delay(5000);//time to connect

  if (connected) {
    Serial.println("Connected Succesfully!");
  }
}

void loop() {

  if (SerialBT.connected())
  {
    digitalWrite(17, LOW);//turn on
    digitalWrite(16, HIGH);//turn off
  }
  else
  {
    digitalWrite(17, HIGH);//turn off
    digitalWrite(16, LOW); //turn on
  }

  if (Serial.available()) {
    SerialBT.write(Serial.read());
  }
  if (SerialBT.available()) {
    Serial.write(SerialBT.read());
  }
  delay(20);
}