T-vK / ESP32-BLE-Keyboard

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

BLE Disconnect command and reconnect. #174

Closed nbaddorf closed 2 years ago

nbaddorf commented 2 years ago

I had a really hard time figuring this out but if you modify the BleKeyboard.cpp file and edit void BleKeyboard::end(void) { } with void BleKeyboard::end(void) { BLEDevice::deinit(); } Now you should be able to disconect ble. Right now, the program will auto reconnect so comment out advertising->start(); with //advertising->start(); in the function void BleKeyboard::onDisconnect(BLEServer* pServer) {

To use this, you have to start advertizing the service with bleKeyboard.begin();. To stop BLE, run bleKeyboard.end();. To restart BLE simply run bleKeyboard.begin(); again.

I think this would be a good addition to the main code.