max22- / ESP32-BLE-MIDI

An Arduino library to use Midi over BLE (Bluetooth Low Energy), on ESP32 boards
MIT License
214 stars 27 forks source link

Callbacks are never called #5

Closed buzz-dk closed 2 years ago

buzz-dk commented 2 years ago

Hello Maxime. Using your example code 04-Dump-Messages.ino with an ESP32 az-delivery-devkit-v4 board I found the following: 1: Callbacks for connect and disconnect were never called. 2: The board freezes on disconnect, ie it refuses to establish another connection.

I have fixed my problem by defining the callbacks before calling .begin() I also added a restart command to the disconnect callback. At least it can be used as a temporary solution.

I hope you find this useful. Thanks for sharing your code. Example shown below. Best regards Kim

void setup() { Serial.begin(115200); BLEMidiServer.setOnConnectCallback([]() { Serial.println("Connected"); }); BLEMidiServer.setOnDisconnectCallback([]() { Serial.println("Disconnected"); ESP.restart(); }); BLEMidiServer.begin("MIDI device"); BLEMidiServer.setNoteOnCallback(onNoteOn); ........

max22- commented 2 years ago

Hi Kim, thank you very much for spotting these bugs, and the information you provided ! I have corrected them, and published the code on the arduino library manager and platformio. Now the example works without needing to modify it, and we can connect and disconnect as much as we want. Can you tell me if it works also for you ? Best regards, Maxime

buzz-dk commented 2 years ago

Hi Maxime I tested your solution 0.2.2 with the ESP32 az-delivery-devkit-v4 on PlatformIO, and I can confirm that It now functions as expected: 1: Callbacks for connect and disconnect are called even when defined later than the .begin() call 2: A disconnect do no longer freeze the board. Many thanks!! Cheers Kim

max22- commented 2 years ago

Ok cool ! cheers, Maxime