arduino-esp32
arduino-esp32 copied to clipboard
Bluetooth Classic Master Mode not Functioning after Board Update
Board
ESP32 WROVER E
Device Description
ESP32 WROVER. No attached hardware.
Hardware Configuration
No connections. Just the USB connection to the computer.
Version
v3.0.3
IDE Name
Arduino IDE
Operating System
Windows 11
Flash frequency
80MHz
PSRAM enabled
yes
Upload speed
921600
Description
When I use the example programs for Bluetooth Classic, the slave device works as expected. The master device does not connect to the slave device. I am using the SerialToSerialBT.ino and SerialToSerialBTM.ino sketches. This is a new problem since updating the board drivers in the IDE.
Sketch
// This example code is in the Public Domain (or CC0 licensed, at your option.)
// By Victor Tchistiak - 2019
//
// This example demonstrates master mode Bluetooth connection to a slave BT device
// defined either by String "slaveName" by default "ESP32-BT-Slave" or by MAC address
//
// This example creates a bridge between Serial and Classical Bluetooth (SPP)
// This is an extension of the SerialToSerialBT example by Evandro Copercini - 2018
//
// DO NOT try to connect to phone or laptop - they are master
// devices, same as the ESP using this code - you will be able
// to pair, but the serial communication will NOT work!
//
// You can try to flash a second ESP32 with the example SerialToSerialBT - it should
// automatically pair with ESP32 running this code
// Note: Pairing is authenticated automatically by this device
#include "BluetoothSerial.h"
#define USE_NAME // Comment this to use MAC address instead of a slaveName
// Check if Bluetooth is available
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
// Check Serial Port Profile
#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Port Profile for Bluetooth is not available or not enabled. It is only available for the ESP32 chip.
#endif
BluetoothSerial SerialBT;
#ifdef USE_NAME
String slaveName = "ESP32-BT-Slave"; // Change this to reflect the real name of your slave BT device
#else
String MACadd = "AA:BB:CC:11:22:33"; // This only for printing
uint8_t address[6] = {0xAA, 0xBB, 0xCC, 0x11, 0x22, 0x33}; // Change this to reflect real MAC address of your slave BT device
#endif
String myName = "ESP32-BT-Master";
void setup() {
bool connected;
Serial.begin(115200);
SerialBT.begin(myName, true);
SerialBT.deleteAllBondedDevices(); // Uncomment this to delete paired devices; Must be called after begin
Serial.printf("The device \"%s\" started in master mode, make sure slave BT device is on!\n", myName.c_str());
#ifndef USE_NAME
SerialBT.setPin(pin);
Serial.println("Using PIN");
#endif
// connect(address) is fast (up to 10 secs max), connect(slaveName) is slow (up to 30 secs max) as it needs
// to resolve slaveName to address first, but it allows to connect to different devices with the same name.
// Set CoreDebugLevel to Info to view devices Bluetooth address and device names
#ifdef USE_NAME
connected = SerialBT.connect(slaveName);
Serial.printf("Connecting to slave BT device named \"%s\"\n", slaveName.c_str());
#else
connected = SerialBT.connect(address);
Serial.print("Connecting to slave BT device with MAC ");
Serial.println(MACadd);
#endif
if (connected) {
Serial.println("Connected Successfully!");
} else {
while (!SerialBT.connected(10000)) {
Serial.println("Failed to connect. Make sure remote device is available and in range, then restart app.");
}
}
// Disconnect() may take up to 10 secs max
if (SerialBT.disconnect()) {
Serial.println("Disconnected Successfully!");
}
// This would reconnect to the slaveName(will use address, if resolved) or address used with connect(slaveName/address).
SerialBT.connect();
if (connected) {
Serial.println("Reconnected Successfully!");
} else {
while (!SerialBT.connected(10000)) {
Serial.println("Failed to reconnect. Make sure remote device is available and in range, then restart app.");
}
}
}
void loop() {
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
Serial.write(SerialBT.read());
}
delay(20);
}
Debug Message
No error message was given. It just would not connect to any device.
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- [X] I confirm I have checked existing issues, online documentation and Troubleshooting guide.
The security aspects of BT have changed significantly between 2.x and 3.x. Make sure you are using the example sketches from the appropriate version.
The example has not been updated on GitHub. It still has a copyright of 2019. It does not work with the new security apparently. I rolled back to version 2.0.17, and it works fine.
I am willing to use the new protocols, if they are indeed an improvement, but there seems to be no instructions on how to use them. If there are, where are they?
I will continue to use the 2.0.17 version, because it works.
Andrew Overton, Sr. Adjunct Professor Department of Electrical & Computer Engineering and Computer Science @.*** 601-672-7437
On Wed, Aug 21, 2024 at 11:14 AM lbernstone @.***> wrote:
The security aspects of BT https://github.com/espressif/arduino-esp32/tree/master/libraries/BluetoothSerial#bluetooth-serial-library have changed significantly between 2.x and 3.x. Make sure you are using the example sketches from the appropriate version.
— Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/10214#issuecomment-2302471766, or unsubscribe https://github.com/notifications/unsubscribe-auth/BDNO2E4TPJ2TX7CTOK2EDD3ZSS4GXAVCNFSM6AAAAABM4CABHGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBSGQ3TCNZWGY . You are receiving this because you authored the thread.Message ID: @.***>
The copyright may not have changed, but the examples certainly have been updated to reflect the changes with SSP. Look at the blame on the files. The link I posted above explains how to use SSP.
I copied the examples from GitHub and ran them. They do not connect to each other. I do not know what I am doing wrong. There are no errors in compilation. Do the new libraries just not work with the board I am using?
I am not interested in using SSP. The application that I am trying to create has no need for the security. It is the section on getting two ESP32's to communicate that I am interested in. There are no instructions in the link on how to use that.
Name resolution appears to not be working. Can @P-R-O-C-H-Y or @me-no-dev take a look? Works fine when given an address.
Can you please help with triage @P-R-O-C-H-Y? Thanks
Please try with actual Arduino core 3.1.3 and 3.2.0-rc2
Closing since no feedback. If the issue still exists with actual Arduino core 3.2.0 feel free to ask to reopen