Bluetooth Serial Class of Device Incorrect and Cannot be Changed
Posted: Fri Feb 24, 2023 9:13 am
On ESP32 Arduino Core version 2.0.0 and newer, the class of device (COD) for classic bluetooth serial is incorrectly set.
Whereas on v1.0.6, the class of device is set to that of a PC/PDA and also allows changing it inside the BluetoothSerial.cpp file.
The exact same code is run between v1.0.6 and newer, yet the newer versions fail to set the COD and also cannot be changed:
esp_bt_cod_t cod;
cod.major = 0b00001;
cod.minor = 0b000100;
cod.service = 0b00000010110;
if (esp_bt_gap_set_cod(cod, ESP_BT_INIT_COD) != ESP_OK) { log_e("set cod failed"); return false; }
The class of device broadcasted as displayed in Bluetooth Android apps is: 7396 (0x1F00) which is incorrect.
I have wired up a multiple ESP32s which includes multiple ESP-WROOM-32D and also ESP-WROOM-32E, all have the same issue, and all work with v1.0.6 to correctly display the COD
Do note I have had to add disableCore0WDT into the sketch since v2.0.0 and newer sets off the watchdog reset when setting up the bluetooth connection.
Sketch
Debug Message
[ 1485][BluetoothSerial.cpp:263] esp_spp_cb(): ESP_SPP_INIT_EVT
[ 1487][BluetoothSerial.cpp:270] esp_spp_cb(): ESP_SPP_INIT_EVT: slave: start
[ 1492][BluetoothSerial.cpp:397] esp_spp_cb(): ESP_SPP_START_EVT
[ 1496][BluetoothSerial.cpp:685] _init_bt(): device name set
[ 1503][BluetoothSerial.cpp:571] esp_bt_gap_cb(): ESP_BT_GAP_CONFIG_EIR_DATA_EVT: stat:0 num:4
Has anyone else had this issue or found a fix for it?
Whereas on v1.0.6, the class of device is set to that of a PC/PDA and also allows changing it inside the BluetoothSerial.cpp file.
The exact same code is run between v1.0.6 and newer, yet the newer versions fail to set the COD and also cannot be changed:
esp_bt_cod_t cod;
cod.major = 0b00001;
cod.minor = 0b000100;
cod.service = 0b00000010110;
if (esp_bt_gap_set_cod(cod, ESP_BT_INIT_COD) != ESP_OK) { log_e("set cod failed"); return false; }
The class of device broadcasted as displayed in Bluetooth Android apps is: 7396 (0x1F00) which is incorrect.
I have wired up a multiple ESP32s which includes multiple ESP-WROOM-32D and also ESP-WROOM-32E, all have the same issue, and all work with v1.0.6 to correctly display the COD
Do note I have had to add disableCore0WDT into the sketch since v2.0.0 and newer sets off the watchdog reset when setting up the bluetooth connection.
Sketch
Code: Select all
#include <BluetoothSerial.h>
BluetoothSerial MyBT;
void setup()
{
disableCore0WDT();
Serial.begin(115200);
MyBT.begin("My BT Name");
}
void loop()
{
}
[ 1485][BluetoothSerial.cpp:263] esp_spp_cb(): ESP_SPP_INIT_EVT
[ 1487][BluetoothSerial.cpp:270] esp_spp_cb(): ESP_SPP_INIT_EVT: slave: start
[ 1492][BluetoothSerial.cpp:397] esp_spp_cb(): ESP_SPP_START_EVT
[ 1496][BluetoothSerial.cpp:685] _init_bt(): device name set
[ 1503][BluetoothSerial.cpp:571] esp_bt_gap_cb(): ESP_BT_GAP_CONFIG_EIR_DATA_EVT: stat:0 num:4
Has anyone else had this issue or found a fix for it?