ESP32-BLE-Keyboard icon indicating copy to clipboard operation
ESP32-BLE-Keyboard copied to clipboard

Won't re-connect on Windows 10 after Power Cycle Off-On Release v0.3.0

Open creepscompilation opened this issue 2 years ago • 13 comments

I am in the final phase of testing and I have to use release v0.3.0 to get Android to work at all..

So, with release v0.3.0, Android and Apple iOS work GREAT !!! On Windows 10 however, I can PAIR and Connect OK, and the BLE Keyboard works GREAT, until I reset the ESP32 module either power off-on, or boot button. After that, "isConnected" comes up as connected, but no keyboard data outputs to Windows 10.

I am forced to UNPAIR the BLE keyboard from Windows 10, the PAIR again. This test is repeatable and confirmed. This probem does not exist with Android or Apple iOS, only Windows 10.

creepscompilation avatar Jun 15 '22 19:06 creepscompilation

Correction: Won't re-connect on Windows 8 also.. Same issue with Windows 10, Windows 8

creepscompilation avatar Jun 15 '22 20:06 creepscompilation

RESOLVED: I took the advice from SunandMittal..

Starting with release v0.3.2 filename = "BleKeyboard.cpp"

Find this line: pSecurity->setAuthenticationMode(ESP_LE_AUTH_REQ_SC_MITM_BOND);

Replace the above line to the following from release v0.3.0 pSecurity->setAuthenticationMode(ESP_LE_AUTH_BOND);

So, far.. Android connects, re-connects, keyboard codes work Apple iOS connects, re-connects, keyboard codes work Windows 10 connects, re-connects, keyboard codes work

creepscompilation avatar Jun 15 '22 20:06 creepscompilation

I have version v0.3.0 with this exact same issue. What do I need to do to fix it? In v0.3.0, BleKeyboard.cpp line 123 is "pSecurity->setAuthenticationMode(ESP_LE_AUTH_BOND);". I tried replacing with 'pSecurity->setAuthenticationMode(ESP_LE_AUTH_REQ_SC_MITM_BOND);' but that does not do anything. Any advice please! Thanks :-)

mvermand22 avatar Jul 01 '22 15:07 mvermand22

Hello mvermand22,

I started with v0.3.2, then I changed that line in the code, I did not test this on any earlier releases. I have attached the library that I modified, NOTE: I call it v0.3.3 for my own reference, this is NOT an official release from this GIT HUB page.

ESP32-BLE-Keyboard 0.3.3.zip

creepscompilation avatar Jul 01 '22 15:07 creepscompilation

Hello mvermand22,

I started with v0.3.2, then I changed that line in the code, I did not test this on any earlier releases. I have attached the library that I modified, NOTE: I call it v0.3.3 for my own reference, this is NOT an official release from this GIT HUB page.

ESP32-BLE-Keyboard 0.3.3.zip

thanks, this worked for me!

jnsw avatar Jan 17 '23 20:01 jnsw

On Windows 11 issue still remains. On the first connection the keyboard works, however if it disconnects, and connects back, no keys are sent. Does anyone know any tool that will log the messages from BT devices on Win 11? I check the system logs, but they only show when the device was first paired.

ekoslav avatar Jan 18 '23 00:01 ekoslav

I had the same problem and created just an account for this. Here is the solution: https://github.com/nkolban/esp32-snippets/issues/632

Open bleKeyboard.cpp and add the two lines to the onConnect() function.

uint8_t val[] = {0x01, 0x00};
desc->setValue(val, 2);

The whole function should look like this:

void BleKeyboard::onConnect(BLEServer* pServer) {
  this->connected = true;
    
#if !defined(USE_NIMBLE)

        uint8_t val[] = {0x01, 0x00};
	BLE2902* desc = (BLE2902*)this->inputKeyboard->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
	desc->setNotifications(true);
        desc->setValue(val, 2);
	desc = (BLE2902*)this->inputMediaKeys->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
	desc->setNotifications(true);
        desc->setValue(val, 2);
#endif // !USE_NIMBLE

}

Update: Sorry my fault. It is the onConnect() function.

mayaku2go avatar Jan 21 '23 08:01 mayaku2go

@mayaku2go : you did not add the lines you recommend to add. Where should they be ? At the beginning ? At the end ?

vcchm avatar Jan 21 '23 17:01 vcchm

@vcchm My fault. Was the wrong function. I updated the code ^^

mayaku2go avatar Jan 21 '23 20:01 mayaku2go

Thanks ! Your correction only changes the code when not in the "Nimble" mode. But the problem happens whatever the mode - Nimble or not. Are you sure you changed the code enough?

vcchm avatar Jan 22 '23 07:01 vcchm

Also are you sur you dont need desc->setValue(val, 2); after the first desc->setNotifications(true); too ???

vcchm avatar Jan 22 '23 08:01 vcchm

Haven't tested it yet as I still don't understand BLE completely XD Maybe one of the developers are able to answer this question. It worked for me and I am trying to establish a secure connection with no input or output and static passkey right now. But this is a point worth trying.

mayaku2go avatar Jan 22 '23 09:01 mayaku2go

@vcchm You are right. Without the second desc->setValue(val, 2); the ESP32 isn't recognized as an HID Keyboard. Code is updated ^^

mayaku2go avatar Jan 25 '23 13:01 mayaku2go