Comments (22)
@MicroMidi
Check the proposed changes in this fork https://github.com/RobertoHE/Arduino-BLE-MIDI before that I will do a pull request to official repo.
from arduino-ble-midi.
Hi @MicroMidi thanks for the question.
Quick question before deep diving into the issue: do you get a disconnect event?
from arduino-ble-midi.
Hi @lathoub, thanks for taking the time and effort to help me out on my issue!
My code ist mainly based on your BLE-MIDI client example. I uploaded it to my GitHub project page - if you want to have a look at it.
This is an extract of the log-messages on the serial port:
**__Advertised Device found: Name: ES3-249F, Address: e4:b3:89:86:ab:f8, serviceUUID: 6acc5540-e631-4069-944d-b8ca7598ad50
Advertised Device found: Name: Adio Air GT MIDI, Address: 44:91:60:00:8c:35, serviceUUID: 03b80e5a-ede8-4b33-a751-6ce34ec4c700
Found MIDI Service
---------CONNECTED---------
Connected to: Adio Air GT MIDI / 44:91:60:00:8c:35
First run
millis(): 4006
t0: 3605
SYSEX: (10 bytes) F0 42 30 0 1 41 42 0 0 F7
MIDI message received!
SYSEX: (8 bytes) F0 42 30 0 1 41 23 F7
MIDI message received!
---------NOT CONNECTED---------
Scanning...
Advertised Device found: Name: , Address: 5f:6a:6b:af:fb:13, manufacturer data: 4c000c0e00f5d4b1e0fa48b072658c99724f1006461e2c8deee1
Advertised Device found: Name: Mi Smart Band 4, Address: e7:ec:4c:58:4e:a3, manufacturer data: 570102ffffffffffffffffffffffffffffffff01e7ec4c584ea3, serviceUUID: 0xfee0
Advertised Device found: Name: F8B3C549AA0F33A3E9, Address: e7:e7:f6:16:5a:e0, appearance: 0, manufacturer data: a705051001000000000000021f00ca, serviceUUID: 0xfe07, txPower:
Advertised Device found: Name: , Address: 5f:6a:6b:af:fb:13, manufacturer data: 4c000c0e00f6d4f236b6b1f52585778d64931006461e2c8deee1
Advertised Device found: Name: Adio Air GT MIDI, Address: 44:91:60:00:8c:35, serviceUUID: 03b80e5a-ede8-4b33-a751-6ce34ec4c700
Found MIDI Service
---------CONNECTED---------
First run
millis(): 117406
t0: 117005
The first connection shows that the Adio amp is connected and it replys with SysEx-messages to MIDI requests when the loop() is entered for the first time after the bluetooth connection is established. When the amp is switched off and on the second connection doesn't log the device that is connected with the client. To me it looks that some client information is cached. If I switch external MIDI-devices then the BLE-MIDI client shows device information also in a re-connect scenario.
I hope that these information snippets are helpful for your investigations - thanks in advance for your great support!
Bernd
from arduino-ble-midi.
I'm going to bring in @RobertoHE who wrote the client part of the library, maybe he sees what is happening
from arduino-ble-midi.
Can you alter:
Arduino-BLE-MIDI/src/hardware/BLEMIDI_Client_ESP32.h
Lines 333 to 346 in 5c42e14
with
void onDisconnect(BLEClient *pClient)
{
if (_bluetoothEsp32)
{
_bluetoothEsp32->disconnected();
// Try reconnection or search a new one
_bluetoothEsp32->scan();
}
}
I can't test it on my side, but worth trying
from arduino-ble-midi.
Thanks again for your support @lathoub! I tried your suggestion - but I didn't solve my problem. Nevertheless the onDisconnect() method was a good hint to try out some other approaches myself ... and what finally did the trick for me was to delete and create the NimBLEDevice-client. Now it looks like the client is re-instantiated from scratch after a re-connect and everything works perfectly now.
This is the current code I use with the added "Renew Client" code snippet:
void onDisconnect(BLEClient *pClient)
{
if (_bluetoothEsp32)
{
_bluetoothEsp32->disconnected();
// Try reconnection or search a new one
_bluetoothEsp32->scan();
}
// Renew Client
NimBLEDevice::deleteClient(pClient);
NimBLEDevice::createClient();
//Try reconnection or search a new one
NimBLEDevice::getScan()->start(1, scanEndedCB);
}
I guess that this is not a very smart approach because other MIDI devices may not need this kind of "hard reset" while reconneting. But for me it works without any problems.
Thanks again for your great support and kind regards
Bernd
from arduino-ble-midi.
Great - happy you were to able to fix it.
Please create a PR, so i can review the changes and add it to the code-base
from arduino-ble-midi.
I'm quite new to GitHub - so I had to google for the term "PR" - it seems to be a "Pull Request" where I fork your code into my own repository and adopt my changes in that environment, right? I will try to make this happen, cross your fingers for me;-)
Thanks and greets, Bernd
from arduino-ble-midi.
... I created a PR with the modified code. Can you please have a look if everything was prepared as expected?
from arduino-ble-midi.
I'm quite new to GitHub - so I had to google for the term "PR" - it seems to be a "Pull Request" where I fork your code into my own repository and adopt my changes in that environment, right? I will try to make this happen, cross your fingers for me;-)
:-) learn something new every day 👍
from arduino-ble-midi.
The PR has not yet shown up in this repo. I did see it in your repo, now bring it over to this repo
from arduino-ble-midi.
Hi @MicroMidi and @lathoub
Be carefull with this change (it may be a correct solution, of course):
This is the current code I use with the added "Renew Client" code snippet:
void onDisconnect(BLEClient *pClient) { if (_bluetoothEsp32) { _bluetoothEsp32->disconnected(); // Try reconnection or search a new one _bluetoothEsp32->scan(); }
// Renew Client NimBLEDevice::deleteClient(pClient); NimBLEDevice::createClient();
//Try reconnection or search a new one NimBLEDevice::getScan()->start(1, scanEndedCB); }
I guess that this is not a very smart approach because other MIDI devices may not need this kind of "hard reset" while reconneting. But for me it works without any problems.
It affects to the next part of the code:
Arduino-BLE-MIDI/src/hardware/BLEMIDI_Client_ESP32.h
Lines 484 to 514 in 5c42e14
These lines of code try to reconnect the device using the previous info of the device. This method is recommended by nimBLE lib because (theoretically) saves time and power because skips send some initial config messages.
Your solution may be valid too, but it may cause some little delays after a reconnection because need a little bit more time than a reconnection. They may be inappreciable but it is a thing to consider.
If the solution that propose @MicroMidi is accepted for a merge, maybe the lines that I put before may be removed from the code because the client never can perform a reconnection because the client will removed after a disconnection,
from arduino-ble-midi.
And it may be recommended add _client = nullptr;
too after NimBLEDevice::deleteClient(pClient); NimBLEDevice::createClient();
from arduino-ble-midi.
@RobertoHE: Thanks for the clarification ... now I understand another concept of your BLE MIDI Client code.
To me it seems now that my proposed code change enforces that the BLE connection will always be built up from scratch - and this makes the part of the code, that you mentioned in your previous post, obvious. I guess that 99% of all MIDI servers can deal with the reconnection approach without any problems - so we should definitely keep this functionality and discard my code change.
To provide some flexibility for the library users in terms of reconnect behaviour a possible approach could be to declare a preprocessing option (“#define BLEMIDI_CLIENT_DISABLERECONNET”) in the header file of the BLE MIDI client and let the library user decide if the functionality should be activated or not (with default active!). This will have no implications for all current library user and provides an option for users that observe problems with the reconnection functionality. Do you think that this could be a practicable solution?
Thanks Bernd
from arduino-ble-midi.
Hi @MicroMidi .
Let me some days for implemets the changes.
from arduino-ble-midi.
Thanks @RobertoHE , no need to hurry - please take all the time you need!
from arduino-ble-midi.
@RobertoHE
Thanks for your time and effort! When I use your updated library then the bluetooth scan stops after disconnecting the bluetooth server. The scan runs exactly once after the disconnect happens and then the scan stops. I haven't found out why - but it happens identically with two different amps that I tested as bluetooth server...
from arduino-ble-midi.
Hi again @MicroMidi
Sorry for the delay.
I added your changes to code.
Would you check the repo again? Uncomment this line before compile https://github.com/RobertoHE/Arduino-BLE-MIDI/blob/ebe18daaea8b1cea0826bbeae893402d12b73f2c/src/hardware/BLEMIDI_Client_ESP32.h#L132
If it works, I will pull request the changes to main repo.
from arduino-ble-midi.
from arduino-ble-midi.
I have proposed a pull request, @lathoub.
Would you check and merge it to the main repo?
Thanks.
from arduino-ble-midi.
@RobertoHE thank you for the work, looks like it works - yeah! Checked and merged.
(thank you @MicroMidi for raising the issue and testing)
With this done, I will create a new release (and make available in the Arduino library)
from arduino-ble-midi.
@lathoub @RobertoHE : This is pretty perfect - thanks for incorporating my request in an official release – it works really great and reliable now!
from arduino-ble-midi.
Related Issues (20)
- Password when pairing. HOT 3
- esp32 BLE-Midi and BluetoothSerial in the same project HOT 2
- decuple from midi transport? HOT 1
- BLE MIDI Client, get servers list HOT 5
- BLE MIDI Client, ESP32-S3, keeps sending serial when not connected HOT 5
- Midi steps audible when sending a stream of CC messages for volume control HOT 8
- BLE-MIDI client: Changes in NimBLE version 1.4.1 HOT 3
- Problem: BLEMIDI_CREATE_INSTANCE with custom names HOT 4
- Compatibility with Arduino GIGA (Arduino-mbed)
- Wrong channel number on polyphony?
- Renaming it Self and loosing connection if either Serial.begin() or Serial1.begin() is used
- Renaming it self and loosing connection if Serial1 or Serial is used.
- Active Sensing HOT 2
- BLE Client Problem with Adafruit TinyUSB HOT 2
- Error compiling on Nano 33 BLE HOT 1
- Trying to get bluetooth midi for Arduino Nano 33 BLE sense rev2 HOT 2
- Issue with Ableton and midi "feedback" HOT 6
- Can't compile anymore on arduino 2.3 - conversion from 'String' to non-scalar type 'std::string' HOT 3
- Bluetooth pairing for Arduino nano 33 BLE // auto connect with macOS HOT 5
- Data is “swallowed”...?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino-ble-midi.