T-vK / ESP32-BLE-Keyboard

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

How to put ESP32 in 'pairing mode' #147

Open joostbijl opened 2 years ago

joostbijl commented 2 years ago

Hi,

i have created a set of handlebar buttons for navigating on my motorcycle, see details here: https://jaxeadv.com/gear-gadgets/navigation-setup/handlebar-buttons/. This library is really useful for that, i'm a big fan!

What i can't seem to work out is how to pair the esp32 to a new phone. I'm looking for the way to put the esp32 in pairing mode so that i can connect it to a different phone (forgetting the previously connected phone).

I'm assuming it has to do with the BLEScan method? But i'm probably missing something, because all the info i can find seems very convoluted for the simple thing i'm trying to do.

Thanks!

sivar2311 commented 2 years ago

Hi @joostbijl ! That is a very nice project! 👍

I'm not a BLE expert and maybe I don't understand the question correctly, but the BleKeyboard is automatically in pairing mode unless there is a connection.

Have you tried the BleKeyboard in NimBLE mode as well?

joostbijl commented 2 years ago

Hi @sivar2311! Thanks, it's really useful to control your phone with your motorcycle gloves on ;)

It does indeed accept new connections when it's not connected!.

Now i have the issue that i want to remove the other phone i connected it to. (or: just remove every existing connection).

Earlier today i used NimBLE, but then the esp would connect, but not send actual keystrokes. I reverted back to the original library and now it works. Did not investigate further. Would it help you if i did?

sivar2311 commented 2 years ago

Please download the latest beta version and activate the NimBLE-Mode (uncomment the 2nd line in BleKeyboard.h)

There are a lot of changes since the last official release. I think this will fix your issues.

joostbijl commented 2 years ago

NimBLE works, after i have removed the esp from my phone and reconnected.

sivar2311 commented 2 years ago

Does it mean the latest beta solved the issue?

joostbijl commented 2 years ago

The original issue is not solved, but not really necessary since you can 'forget' devices from your phone just as easily.

Using NimBLE i can now run the ble_store_clear() command, but that does not appear to clear all bonds stored on the esp.

Guillemete commented 2 years ago

Maybe you can reset the internal memory on the ESP where the pairing info if stored?

Guillemete commented 2 years ago

https://github.com/espressif/arduino-esp32/blob/master/libraries/BluetoothSerial/examples/bt_remove_paired_devices/bt_remove_paired_devices.ino

this might help. havent tried it yet

sivar2311 commented 2 years ago

NimBLE supports this: NimBLEDevice::deleteAllBonds();

But I can't say how it is done with the standard BLE library.

Guillemete commented 2 years ago

https://icircuit.net/esp-idf-bluetooth-remove-bonded-devices/3040