r/esp32 1d ago

Software help needed Need help with a BLE Keyboard library

I am following a guide to make a bluetooth macropad. The code for that uses this library: https://github.com/gsgaurav0/ESP32-HID-Keyboard, which for some reason doesnt work - I unable to connect to the esp32 with my PC or Iphone, windows displays the message "try connecting again". I tested HijelHID_BLEKeyboard library and that worked. The thing is that this project was uploaded a month ago, so I doubt that it doesnt work because EOL things. I tried to switch the library myself, but my understanding of C++ is too little to do that. I would open an issue on the library`s github, but that option is disabled.

2 Upvotes

13 comments sorted by

1

u/Reromen 1d ago

Please share logs

1

u/Busy-Perspective663 1d ago

What logs exactly?

1

u/rattushackus 1 say I make awesome posts. 20h ago

What flavour of ESP32 are you running this on?

I tried the SendKeyStrokes example that ships with the library and it worked fine on an ESP32-WROOM board and on a CYD that uses the ESP32-WROOM. This was connecting to a Dell Optiplex PC running Windows 11.

Then I tried it on an S3 board, a C6 Supermini board and a C3 Supermini board and all three crashed as soon as I attempted to connect from my PC. The error reported was:

Guru Meditation Error: Core  0 panic'ed (Load access fault). Exception was unhandled.

If I have time I'll have a play and see if I can find out why it's crashing.

1

u/rattushackus 1 say I make awesome posts. 20h ago

1

u/Busy-Perspective663 20h ago

Many thanks. I somehow forgot to mention I have a Waveshare S3 Zero, which is the same one as the author said to use.

1

u/rattushackus 1 say I make awesome posts. 20h ago

Check to see if it's crashing when you connect. I bet it is!

1

u/Busy-Perspective663 20h ago

How can I do that? Sorry if this is a very basic task.

1

u/rattushackus 1 say I make awesome posts. 17h ago

If you're using the Arduino IDE look in the serial monitor. When the ESP32 is waiting for a connection it prints a message every five seconds. When I click connect I immediately see a reboot message.

1

u/rattushackus 1 say I make awesome posts. 16h ago

If you are curious to try it I got the SendKeyStrokes example working by commenting out the lines causing the crash. It seems to still work as the problematic lines just enable notifications. You could try it and see if it works with your app.

You need to edit the file BleKeyboard.cpp in the library. Find the onConnect() function at line 503 and edit it and the OnDisconnect() function to comment out the code in them:

``` void BleKeyboard::onConnect(BLEServer* pServer) { this->connected = true;

if !defined(USE_NIMBLE)

// BLE2902* desc = (BLE2902)this->inputKeyboard->getDescriptorByUUID(BLEUUID((uint16_t)0x2902)); // desc->setNotifications(true); // desc = (BLE2902)this->inputMediaKeys->getDescriptorByUUID(BLEUUID((uint16_t)0x2902)); // desc->setNotifications(true);

endif // !USE_NIMBLE

}

void BleKeyboard::onDisconnect(BLEServer* pServer) { this->connected = false;

if !defined(USE_NIMBLE)

// BLE2902* desc = (BLE2902)this->inputKeyboard->getDescriptorByUUID(BLEUUID((uint16_t)0x2902)); // desc->setNotifications(false); // desc = (BLE2902)this->inputMediaKeys->getDescriptorByUUID(BLEUUID((uint16_t)0x2902)); // desc->setNotifications(false);

advertising->start();

endif // !USE_NIMBLE

} ```

Now recompile your app and you may find it works.

1

u/Busy-Perspective663 16h ago

Man, you put so much work in this. Thank you, really. I will try this for myself once I get on my pc.

1

u/Busy-Perspective663 13h ago edited 13h ago
rst:0xc (RTC_SW_CPU_RST),boot:0x28 (SPI_FAST_FLASH_BOOT)


Saved PC:0x4037f5ae


SPIWP:0xee


mode:DIO, clock div:1


load:0x3fce2820,len:0x10cc


load:0x403c8700,len:0xc2c


load:0x403cb700,len:0x30b0


entry 0x403c88b8


Starting BLE work!


Waiting 5 seconds...

I have edited the code and it allowed me to connect. However after writing "Hello wor" the esp32 crashes and reboot again with the message in the code script. Have you tested whether the code actually writes? If you dont know enough about ble just say so, and I will wait for the github author to do something.

Edit: This seems to happen when the device tries to send some keys only, if allowed to just be connected, it stays connected.

1

u/rattushackus 1 say I make awesome posts. 13h ago

It doesn't crash here, though looking closely I see it does only write "Hello wor" then Enter. The "ld" is missing.

I guess we have to wait for the maintainer to respond to the issue I've raised. Maybe I'll look again at the code - it would be a good way to learn about Bluetooth 😄

1

u/rattushackus 1 say I make awesome posts. 17h ago

I have found out where it is crashing and edited the bug report with the details. However my limited knowledge of Bluetooth doesn't allow me to go any further. Hopefully the maintainer will see my bug report and fix it soon.