Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 Bluetooth SPP service not started in Master mode (IDFGH-11185) #8748

Closed
3 tasks done
EricHarbers opened this issue Oct 4, 2023 · 1 comment · Fixed by #8806
Closed
3 tasks done

ESP32 Bluetooth SPP service not started in Master mode (IDFGH-11185) #8748

EricHarbers opened this issue Oct 4, 2023 · 1 comment · Fixed by #8806
Assignees
Labels
Area: BT&Wifi BT & Wifi related issues Type: Bug 🐛 All bugs

Comments

@EricHarbers
Copy link

EricHarbers commented Oct 4, 2023

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

Arduino IDE 2.2.1

Espressif SoC revision.

ESP32 V2.0.13

Operating System used.

Windows

How did you build your project?

Eclipse IDE

If you are using Windows, please specify command line type.

None

Development Kit.

ESP32 dev board

Power Supply used.

USB

What is the expected behavior?

I expect that a bluetooth serial slave can connect to the bluetooth serial (SPP) master, which is created on the ESP32 board. The slave should find the bluetooth serial port UUID, and then connect to it, using that UUID.

What is the actual behavior?

Instead, the slave could not connect to the master in the ESP32 board. Because the bluetooth serial UUID is not advertised, the slave can not find the SPP master. So I started checking the bluetoothserial.cpp driver in the ESP 2.0.13 library.
In the function "esp_spp_cb()", at the ESP_SPP_INIT_EVT event, I found that the bluetooth serial service only was started in slave mode, by calling the function "esp_spp_start_srv()". After I changed the code in the ESP_SPP_INIT_EVT to also call the function "esp_spp_start_srv()" in master mode, the slave could connect to the SPP service.

The original code in the "esp_spp_cb()" in BluetoothSerial.cpp is:

static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
{
    switch (event)
    {
    case ESP_SPP_INIT_EVT:
        log_i("ESP_SPP_INIT_EVT");
#ifdef ESP_IDF_VERSION_MAJOR
        esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
#else
        esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
#endif
        if (!_isMaster) {
            log_i("ESP_SPP_INIT_EVT: slave: start");
	    esp_spp_start_srv(ESP_SPP_SEC_NONE, ESP_SPP_ROLE_SLAVE, 0, _spp_server_name);
        }
        xEventGroupSetBits(_spp_event_group, SPP_RUNNING);
        break;

My changed code is:

static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
{
    switch (event)
    {
    case ESP_SPP_INIT_EVT:
        log_i("ESP_SPP_INIT_EVT");
#ifdef ESP_IDF_VERSION_MAJOR
        esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
#else
        esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
#endif
        if (!_isMaster) {
            log_i("ESP_SPP_INIT_EVT: slave: start");
        }
        esp_spp_start_srv(ESP_SPP_SEC_NONE, _isMaster ? ESP_SPP_ROLE_MASTER : ESP_SPP_ROLE_SLAVE, 0, _spp_server_name);
        xEventGroupSetBits(_spp_event_group, SPP_RUNNING);
        break;

As you can see, in the code, the line:
esp_spp_start_srv(ESP_SPP_SEC_NONE, ESP_SPP_ROLE_SLAVE, 0, _spp_server_name);
has been changed to:
esp_spp_start_srv(ESP_SPP_SEC_NONE, _isMaster ? ESP_SPP_ROLE_MASTER : ESP_SPP_ROLE_SLAVE, 0, _spp_server_name);
and is placed outside the if (!_isMaster) { statement.

Attached, my complete project, for the ESP32 board, in a zip file. Also the changed BluetoothSerial.cpp file can be found there.
ESP32_Myomed.zip

Steps to reproduce.

  1. Build the project in the zip file, using the Arduino IDE
  2. Load the bin file into the ESP32 Dev board
  3. Connect to the dev board using a Bluetooth SPP client connection, to a bluetooth connector on eg a PC, with the name "raspberrypi'
  4. The PC app should find the SPP service UUID on the ESP32 dev board:
  5. With the original BluetoothSerial.cpp file, the SPP service can not be found.
  6. With the changed BluetoothSerial.cpp file, the SPP service should be found!!

Debug Logs.

I have not found the solution to the bug using a log.
I found the bug, by looking into the BluetoothSerial.cpp source code.

More Information.

No response

@github-actions github-actions bot changed the title ESP32 Bluetooth SPP service not started in Master mode ESP32 Bluetooth SPP service not started in Master mode (IDFGH-11185) Oct 4, 2023
@nopnop2002
Copy link

This is the place to report ESP-IDF Framework issues.

Arduino Framework issues are better suited here.

https://github.com/espressif/arduino-esp32/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BT&Wifi BT & Wifi related issues Type: Bug 🐛 All bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants