T-vK / ESP32-BLE-Keyboard

Bluetooth LE Keyboard library for the ESP32 (Arduino IDE compatible)
2.28k stars 379 forks source link

Pairing is slow and unable to connect again. ANDROID #247

Closed luissperber closed 11 months ago

luissperber commented 11 months ago

Hi there. I've been having problems with the ESP32 and an Android TV. Firstly, the pairing is slow and sometimes fails (the ESP32 is not discovered). I am completely unable to reconnect unless I remove the ESP from my Android and pair it again.

I've only been trying to send a keypress, so I don't think it's a code problem. I've tried versions 0.2.3, 0.3.0, and 0.3.2 beta, and none of them have worked.

include

const int buttonPin1 = 16; boolean oldPinState1 = LOW;

void setup() { pinMode(buttonPin1, INPUT_PULLDOWN); bleKeyboard.begin(); }

void loop() { if(bleKeyboard.isConnected()) { if (digitalRead(buttonPin1) == HIGH) { if (oldPinState1 == LOW) { bleKeyboard.write(KEY_UP_ARROW); delay (100); bleKeyboard.releaseAll(); } oldPinState1 = HIGH; } else { oldPinState1 = LOW; } delay(10); } }

The interesting thing is that it works on Windows 11. I can pair, shut down, and connect; everything works perfectly.

Do you have any solutions or suggestions? Thanks

luissperber commented 11 months ago

Finally can solve this:

  1. Use NimBLE 1.4.1 and ESP32-BLE-Keyboard 0.3.2b.
  2. Configure it to use NimBLE mode instead of ClassicBLE.
  3. Done!

PS: To activate NimBLE mode: Go to the ESP32-BLE-Keyboard library folder, open BleKeyboard.h, and uncomment the 2nd line: "#define USE_NIMBLE"."

Now Android devices connect almost instantly and reconnect well and fast.