T-vK / ESP32-BLE-Keyboard

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

On version 0.3.0, media button (play/pause) doesn't work after reboot of esp32 w/ Android #189

Open jdeltoft opened 2 years ago

jdeltoft commented 2 years ago

My steps to show the problem. I won't mention pairing, as that doesn't seem related. So after I have a paired esp32 to my android phone, here is what I do:

  1. android bluetooth is on, paired to a ble audio device (logitech speakers for music) and paired to this esp32 as a keyboard (for media controls)
  2. esp32 is on, and is sending "bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE);" every 5 seconds. This is inside a check for "if(bleKeyboard.isConnected())"
  3. everything is working great.
  4. power cycle the est32 by hitting reset button
  5. devices reconnect to each other after just a few seconds over bluetooth, and per logging I see that the isConnected check passes.
  6. KEY_MEDIA_PLAY_PAUSE presses are being logged but are NOT working
  7. After a few logs showing the failure, I turn off bluetooth on android, and turn it back on after just a second or two.
  8. it reconnects again, and now it works for KEY_MEDIA_PLAY_PAUSE

Here is the simple code:

include

BleKeyboard bleKeyboard;

void setup() { Serial.begin(115200); Serial.println("Starting BLE work!"); bleKeyboard.begin(); }

void loop() { if(bleKeyboard.isConnected()) {

delay(1000);

Serial.println("Sending Play/Pause media key...");
bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE);

delay(1000);

}

Serial.println("Waiting 5 seconds..."); delay(5000); }