PlatformIO Community

Trying to implement ESP32 Bluetooth Serial Debug

Hi,

I am currently trying to implement an espressif (esp-idf, NO ARDUINO)
library.

The main functions fo the library are:
-Pair ESP32 with a Phone via Bluetooth

I founded several examples and there are all in Arduino. I WANT TO AVOID
ARDUINO.

Has anybody implemented something like this in the Espressif Framework:

Code in Arduino:

#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);
  SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
}

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

Espressif has example code for the serial port protocol (SPP) at esp-idf/examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor at release/v4.2 · espressif/esp-idf · GitHub. PlatformIO has documentation on ESP-IDF project configuration here. And it also has a BLE example.

Dear maxgerthardt.

Thanks for your repply!!

I just copiled and it works!

This is an example of log:
[5/11 08:39:48.5]I (21347) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:39:48.5]I (21357) : 68 6f 6c 61 0d 0a **
[5/11 08:40:00.9]I (33777) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:40:00.9]I (33777) : 68 6f 6c 61 0d 0a **
[5/11 08:40:01.0]I (33857) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:40:01.0]I (33857) : 68 6f 6c 61 0d 0a **
[5/11 08:40:01.2]I (34037) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:40:01.2]I (34037) : 68 6f 6c 61 0d 0a **
[5/11 08:40:01.3]I (34187) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:40:01.3]I (34187) : 68 6f 6c 61 0d 0a **
[5/11 08:40:01.5]I (34367) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:40:01.5]I (34367) : 68 6f 6c 61 0d 0a **
[5/11 08:40:01.8]I (34577) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:40:01.8]I (34577) : 68 6f 6c 61 0d 0a **
[5/11 08:40:01.9]I (34717) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:40:01.9]I (34717) : 68 6f 6c 61 0d 0a **
[5/11 08:40:02.1]I (34917) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:40:02.1]I (34917) : 68 6f 6c 61 0d 0a **
[5/11 08:40:02.2]I (35057) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:40:02.2]I (35057) : 68 6f 6c 61 0d 0a **
[5/11 08:40:02.4]I (35217) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:40:02.4]I (35217) : 68 6f 6c 61 0d 0a **
[5/11 08:40:02.6]I (35387) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:40:02.6]I (35387) : 68 6f 6c 61 0d 0a **
[5/11 08:40:02.7]I (35557) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:40:02.7]I (35557) : 68 6f 6c 61 0d 0a **
[5/11 08:40:02.9]I (35717) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:40:02.9]I (35717) : 68 6f 6c 61 0d 0a **
[5/11 08:40:03.1]I (35887) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:40:03.1]I (35887) : 68 6f 6c 61 0d 0a **
[5/11 08:40:03.2]I (36017) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:40:03.2]I (36017) : 68 6f 6c 61 0d 0a **
[5/11 08:40:03.4]I (36217) SPP_ACCEPTOR_DEMO: ESP_SPP_DATA_IND_EVT len=6 handle=129
**[5/11 08:40:03.4]I (36217) : 68 6f 6c 61 0d 0a **
[5/11 08:40:57.8]W (90617) BT_RFCOMM: port_rfc_closed RFCOMM connection in state 2 closed: Closed (res: 19)
[5/11 08:40:57.8]I (90617) SPP_ACCEPTOR_DEMO: ESP_SPP_CLOSE_EVT

Thank you very much,

Jorge