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 C3/S3 BLE doesn't work properly compared to ESP32 S1 #7364

Open
1 task done
Seref opened this issue Oct 17, 2022 · 9 comments
Open
1 task done

ESP32 C3/S3 BLE doesn't work properly compared to ESP32 S1 #7364

Seref opened this issue Oct 17, 2022 · 9 comments
Assignees
Labels
Area: BT&Wifi BT & Wifi related issues Status: In Progress Issue is in progress

Comments

@Seref
Copy link

Seref commented Oct 17, 2022

Board

ESP32-C3-DevKitM-1

Device Description

Nothing, just the board itself

Hardware Configuration

It's just creating a BLE Server like in the arduino examples

Version

v2.0.5

IDE Name

PlatformIO

Operating System

Windows 10

Flash frequency

40 Mhz

PSRAM enabled

no

Upload speed

115200

Description

It seems like BLE is kind of broken on the ESP32 C3&S3 compared to the ESP32 OG.

When trying to connect to the device, for once only my phone is able to see the ESP32 C3 not my PC even though I have a Bluetooth 5 card.

In addition to that the ESP32 C3 spits out multiple errors and doesn't connect properly.

The errors are all related to the pairing security:

E (14434) BT_SMP: smp_calculate_link_key_from_long_term_key failed to update link_key. Sec Mode = 2, sm4 = 0x00
E (14435) BT_SMP: smp_derive_link_key_from_long_term_key failed

E (14442) BT_BTM: btm_proc_smp_cback received for unknown device
[ 14177][I][BLEDevice.cpp:249] gapEventHandler(): key type = ESP_LE_KEY_PID
[ 14183][I][BLEDevice.cpp:249] gapEventHandler(): key type = ESP_LE_KEY_PCSRK
[ 14192][I][BLEDevice.cpp:253] gapEventHandler(): ESP_GAP_BLE_AUTH_CMPL_EVT
E (14656) BT_BTM: BTM_GetSecurityFlags false

E (14746) BT_BTM: BTM_GetSecurityFlags false

E (15016) BT_BTM: BTM_GetSecurityFlags false

E (29868) BT_BTM: Device not found

E (29869) BT_HCI: hci connection params reply command error 0x2


Library like ESP32 BLEKeyboard or ESP32 BLE Gamepad don't work at all on the ESP32 C3 and S3.

Sketch

/*
    Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleServer.cpp
    Ported to Arduino ESP32 by Evandro Copercini
    updates by chegewara
*/

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>

// See the following for generating UUIDs:
// https://www.uuidgenerator.net/

#define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE work!");

  BLEDevice::init("ESP32 C3");
  BLEServer *pServer = BLEDevice::createServer();
  BLEService *pService = pServer->createService(SERVICE_UUID);
  BLECharacteristic *pCharacteristic = pService->createCharacteristic(
                                         CHARACTERISTIC_UUID,
                                         BLECharacteristic::PROPERTY_READ |
                                         BLECharacteristic::PROPERTY_WRITE
                                       );

  pCharacteristic->setValue("Hello World says Neil");
  pService->start();
  // BLEAdvertising *pAdvertising = pServer->getAdvertising();  // this still is working for backward compatibility
  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->addServiceUUID(SERVICE_UUID);
  pAdvertising->setScanResponse(true);
  pAdvertising->setMinPreferred(0x06);  // functions that help with iPhone connections issue
  pAdvertising->setMinPreferred(0x12);
  BLEDevice::startAdvertising();
  Serial.println("Characteristic defined! Now you can read it in your phone!");
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(2000);
}

Debug Message

04:35:18.343 ->E (26465) BT_SMP: smp_calculate_link_key_from_long_term_key failed to update link_key. Sec Mode = 2, sm4 = 0x00
04:35:18.343 -> E (26466) BT_SMP: smp_derive_link_key_from_long_term_key failed
04:35:18.343 ->
04:35:18.388 -> E (26474) BT_BTM: btm_proc_smp_cback received for unknown device
04:35:18.621 -> E (26724) BT_BTM: BTM_GetSecurityFlags false
04:35:18.621 ->
04:35:18.668 -> E (26799) BT_BTM: BTM_GetSecurityFlags false
04:35:18.668 ->
04:35:19.043 -> E (27136) BT_BTM: BTM_GetSecurityFlags false
04:35:19.043 ->
04:35:23.695 -> E (31824) BT_BTM: BTM_GetSecurityFlags false
04:35:23.695 ->
04:35:23.883 -> E (31974) BT_BTM: BTM_GetSecurityFlags false
04:35:23.883 ->
04:35:23.883 -> E (31989) BT_BTM: BTM_GetSecurityFlags false
04:35:23.883 ->
04:35:23.930 -> E (32049) BT_BTM: BTM_GetSecurityFlags false
04:35:23.930 ->
04:35:23.977 -> E (32071) BT_BTM: BTM_GetSecurityFlags false
04:35:23.977 ->
04:35:23.977 -> E (32086) BT_BTM: BTM_GetSecurityFlags false
04:35:23.977 ->
04:35:24.022 -> E (32131) BT_BTM: BTM_GetSecurityFlags false
04:35:24.022 ->
04:35:24.067 -> E (32154) BT_BTM: BTM_GetSecurityFlags false
04:35:24.067 ->
04:35:24.067 -> E (32169) BT_BTM: BTM_GetSecurityFlags false
04:35:24.067 ->
04:35:24.067 -> E (32184) BT_BTM: BTM_GetSecurityFlags false
04:35:24.067 ->
04:35:24.114 -> E (32199) BT_BTM: BTM_GetSecurityFlags false
04:35:24.114 ->
04:35:24.114 -> E (32221) BT_BTM: BTM_GetSecurityFlags false
04:35:24.114 ->
04:35:24.114 -> E (32236) BT_BTM: BTM_GetSecurityFlags false
04:35:24.114 ->
04:35:24.162 -> E (32251) BT_BTM: BTM_GetSecurityFlags false
04:35:24.162 ->
04:35:24.162 -> E (32266) BT_BTM: BTM_GetSecurityFlags false
04:35:24.162 ->
04:35:24.255 -> E (32341) BT_BTM: BTM_GetSecurityFlags false
04:35:24.255 ->
04:35:24.255 -> E (32364) BT_BTM: BTM_GetSecurityFlags false
04:35:24.255 ->
04:35:24.255 -> E (32379) BT_BTM: BTM_GetSecurityFlags false

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@newfoxnose
Copy link

I have the similar issue. the T-vK/ESP32-BLE-Keyboard sketch works fine on one board, but won't work on other boards. I can find the device name on PC, but can't pair.

@Jason2866
Copy link
Collaborator

Does the problem still exists with actual core 2.0.7?

@VojtechBartoska VojtechBartoska added Resolution: Awaiting response Waiting for response of author and removed Status: Awaiting triage Issue is waiting for triage labels Apr 19, 2023
@Seref
Copy link
Author

Seref commented Apr 25, 2023

Does the problem still exists with actual core 2.0.7?

Sorry for the late reply. I tried 2.0.8 out and I get the same message with the example sketch above when trying to connect to it.

19:31:19.441 -> Starting BLE work!
19:31:19.441 -> Characteristic defined! Now you can read it in your phone!
19:31:19.441 -> E (18112) BT_SMP: smp_calculate_link_key_from_long_term_key failed to update link_key. Sec Mode = 2, sm4 = 0x00
19:31:19.441 -> E (18113) BT_SMP: smp_derive_link_key_from_long_term_key failed
19:31:19.441 -> 
19:31:19.441 -> E (18119) BT_BTM: btm_proc_smp_cback received for unknown device
19:31:19.674 -> E (18335) BT_BTM: BTM_GetSecurityFlags false
19:31:19.674 -> 
19:31:19.767 -> E (18425) BT_BTM: BTM_GetSecurityFlags false
19:31:19.767 -> 
19:31:20.047 -> E (18695) BT_BTM: BTM_GetSecurityFlags false
19:31:20.047 -> 
19:31:24.798 -> E (23465) BT_BTM: BTM_GetSecurityFlags false
19:31:24.798 -> 
19:31:24.891 -> E (23555) BT_BTM: BTM_GetSecurityFlags false
19:31:24.891 -> 
19:31:24.985 -> E (23645) BT_BTM: BTM_GetSecurityFlags false
19:31:24.985 -> 
19:31:25.124 -> E (23775) BT_BTM: BTM_GetSecurityFlags false
19:31:25.124 -> 
19:31:25.124 -> E (23798) BT_BTM: BTM_GetSecurityFlags false
19:31:25.124 -> 
19:31:25.169 -> E (23813) BT_BTM: BTM_GetSecurityFlags false
19:31:25.169 -> 
19:31:25.216 -> E (23857) BT_BTM: BTM_GetSecurityFlags false
19:31:25.216 -> 
19:31:25.216 -> E (23880) BT_BTM: BTM_GetSecurityFlags false
19:31:25.216 -> 
19:31:25.216 -> E (23895) BT_BTM: BTM_GetSecurityFlags false
19:31:25.216 -> 

Also neither does the T-vK/ESP32-BLE-Keyboard or Mouse/Gamepad libraries work with the ESP32-C3 or S3. Only with the original ESP32. I know that classic is missing with the newer mcus but the BLE stuff should still work right?

@Cengls
Copy link

Cengls commented Jun 16, 2023

I got the same error, in the environment :

vscode plo
windows11
esp32 c3

specifically manifested as a bluetooth mouse can be used, but the keyboard and the gamepad keep flashing links

@VojtechBartoska
Copy link
Contributor

Maybe those issues will be covered by #7867

@VojtechBartoska VojtechBartoska added Status: In Progress Issue is in progress and removed Resolution: Awaiting response Waiting for response of author labels Aug 17, 2023
@Seref
Copy link
Author

Seref commented Aug 17, 2023

I can test out those fixes when they are merged and testable :)

@Seref
Copy link
Author

Seref commented Nov 30, 2023

I still get the same error messages, but now the keyboard library, which wasn't updated since 2021, works.

The only thing that needs to be changed is the AuthenticationMode to ESP_LE_AUTH_BOND from ESP_LE_AUTH_REQ_SC_MITM_BOND .

I tried this change before too, though back then it didn't work. But now a year later and with arduino-esp32 v2.0.14 it seems to work just fine :)

@Seref Seref closed this as completed Nov 30, 2023
@pcace
Copy link

pcace commented Feb 9, 2025

Any news on this? seems to be not fixed.

@SuGlider
Copy link
Collaborator

SuGlider commented Feb 9, 2025

I'll reopen this issue the link it to the NimBLE refactoring effort that is right now under development #9878
@lucasssvaz is in charge of this project and he can test all the examples necessary.

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 Status: In Progress Issue is in progress
Projects
None yet
Development

No branches or pull requests

8 participants