T-vK / ESP32-BLE-Keyboard

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

Can't connect to Android #192

Open vcchm opened 1 year ago

vcchm commented 1 year ago

Hello !

The is a great library which allows using ESP32's BLE very simply. Unfortunately I can't make it work with my Android device.

-Library used is the latest available - i have the issue with 0.31 and 0.3.2 (béta). -I am using a Samsung Note 20 Android Phone. -The Esp device is a Lily TKeyboard with an ESP32C3 chip -The following code can't connect to my Android phone -On the android I have a message "Impossible to connect a new device". Sometimes I am getting a popup asking me to pair the device with my phone, then an error message, -On the ESP side I get these errror messages E (115481) BT_BTM: btm_proc_smp_cback received for unknown device E (145482) BT_BTM: btm_proc_smp_cback received for unknown device E (148363) BT_BTM: Device not found -Athentification mode is following: pSecurity->setAuthenticationMode(ESP_LE_AUTH_REQ_SC_MITM_BOND); -Code used is the follwing simple code - it works perfectly with my PC

include

BleKeyboard bleKeyboard;

void setup() { Serial.begin(115200); Serial.println("Starting BLE work!"); bleKeyboard.begin(); } void loop() { if(bleKeyboard.isConnected()) { Serial.println("Sending 'Hello world'..."); bleKeyboard.print("Hello world"); delay(1000); } Serial.println("Waiting 5 seconds..."); delay(5000); }

vcchm commented 1 year ago

When I use the library 0.3.0 it pairs & works the first time. But when I switch off and on the ESP32, it pairs but the keyboard is not working anymore...

joostbijl commented 1 year ago

The fix with regard to setting a different authentication method (#166 ) works for most scenarios as far as i can see. I suggest to change that in your local copy of the ble keyboard library

This is the change in My Documents\Arduino\libraries\ESP32-BLE-Keyboard-0.3.2-beta\BleKeyboard.cpp. On line 130 change pSecurity->setAuthenticationMode(ESP_LE_AUTH_REQ_SC_MITM_BOND); to pSecurity->setAuthenticationMode(ESP_LE_AUTH_BOND);

I'm not really sure what these authentication modes are and how they affect other systems. But so far so good.

vcchm commented 1 year ago

Thanks. I am using now the last stable version, and generating a new name & Mac adress for each compilation. Then it works for win 10, win 11 and android as well as IPhone.

panakos commented 1 year ago

The fix with regard to setting a different authentication method (#166 ) works for most scenarios as far as i can see. I suggest to change that in your local copy of the ble keyboard library

This is the change in My Documents\Arduino\libraries\ESP32-BLE-Keyboard-0.3.2-beta\BleKeyboard.cpp. On line 130 change pSecurity->setAuthenticationMode(ESP_LE_AUTH_REQ_SC_MITM_BOND); to pSecurity->setAuthenticationMode(ESP_LE_AUTH_BOND);

I'm not really sure what these authentication modes are and how they affect other systems. But so far so good.

This works on all my android devices except lenovo tab m7 that's running android go .it connects 1st time but will not reconnect any asks to be paired again

mayaku2go commented 1 year ago

This should help: https://github.com/mayaku2go/ESP32-BLE-Keyboard/releases/tag/v0.3.2b

panakos commented 1 year ago

This should help: https://github.com/mayaku2go/ESP32-BLE-Keyboard/releases/tag/v0.3.2b

Thanks , I'll give it a try!

panakos commented 1 year ago

This should help: https://github.com/mayaku2go/ESP32-BLE-Keyboard/releases/tag/v0.3.2b

Thanks , I'll give it a try!

Unfortunately it's doing the same . It will work on pairing and will reconnect if you turn off the tablets bluetooth or if you reset the esp32 , but it will ask to be paired again if you power cycle the esp32

gator55 commented 1 month ago

The fix with regard to setting a different authentication method (#166 ) works for most scenarios as far as i can see. I suggest to change that in your local copy of the ble keyboard library

This is the change in My Documents\Arduino\libraries\ESP32-BLE-Keyboard-0.3.2-beta\BleKeyboard.cpp. On line 130 change pSecurity->setAuthenticationMode(ESP_LE_AUTH_REQ_SC_MITM_BOND); to pSecurity->setAuthenticationMode(ESP_LE_AUTH_BOND);

I'm not really sure what these authentication modes are and how they affect other systems. But so far so good.

Now volume control/play/pause works with Xiaomi. Many thanks!