|
75 | 75 | *
|
76 | 76 | * Uncomment what you need
|
77 | 77 | * These are the default values.
|
| 78 | + * You can select some simultaneously. |
78 | 79 | */
|
79 | 80 | #define BLEMIDI_CLIENT_BOND
|
80 | 81 | //#define BLEMIDI_CLIENT_MITM
|
|
86 | 87 | */
|
87 | 88 | static uint32_t userOnPassKeyRequest()
|
88 | 89 | {
|
89 |
| - //FILL WITH YOUR CUSTOM AUTH METHOD or PASSKEY |
| 90 | + //FILL WITH YOUR CUSTOM AUTH METHOD CODE or PASSKEY |
90 | 91 | //FOR EXAMPLE:
|
91 | 92 | uint32_t passkey = 123456;
|
92 | 93 |
|
@@ -117,6 +118,23 @@ static uint32_t userOnPassKeyRequest()
|
117 | 118 | #define BLEMIDI_CLIENT_COMM_LATENCY 0 //
|
118 | 119 | #define BLEMIDI_CLIENT_COMM_TIMEOUT 200 //2000ms
|
119 | 120 |
|
| 121 | +/* |
| 122 | +###### BLE FORCE NEW CONNECTION ###### |
| 123 | +*/ |
| 124 | + |
| 125 | +/** |
| 126 | + * This parameter force to skip the "soft-reconnection" and force to create a new connection after a disconnect event. |
| 127 | + * "Soft-reconnection" save some time and energy in comparation with performming a new connection, but some BLE devices |
| 128 | + * don't support or don't perform correctly a "soft-reconnection" after a disconnection event. |
| 129 | + * Uncomment this define if your device doesn't work propertily after a reconnection. |
| 130 | + * |
| 131 | +*/ |
| 132 | +//#define BLEMIDI_FORCE_NEW_CONNECTION |
| 133 | + |
| 134 | +/** |
| 135 | + * |
| 136 | +*/ |
| 137 | + |
120 | 138 | /*
|
121 | 139 | #############################################
|
122 | 140 | ############ USER DEFINES END ###############
|
@@ -338,8 +356,19 @@ class MyClientCallbacks : public BLEClientCallbacks
|
338 | 356 | if (_bluetoothEsp32)
|
339 | 357 | {
|
340 | 358 | _bluetoothEsp32->disconnected();
|
| 359 | +#ifdef BLEMIDI_FORCE_NEW_CONNECTION |
| 360 | + // Try reconnection or search a new one |
| 361 | + _bluetoothEsp32->scan(); |
| 362 | +#endif // BLEMIDI_FORCE_NEW_CONNECTION |
341 | 363 | }
|
342 | 364 |
|
| 365 | +#ifdef BLEMIDI_FORCE_NEW_CONNECTION |
| 366 | + // Renew Client |
| 367 | + NimBLEDevice::deleteClient(pClient); |
| 368 | + NimBLEDevice::createClient(); |
| 369 | + pClient = nullptr; |
| 370 | +#endif // BLEMIDI_FORCE_NEW_CONNECTION |
| 371 | + |
343 | 372 | //Try reconnection or search a new one
|
344 | 373 | NimBLEDevice::getScan()->start(1, scanEndedCB);
|
345 | 374 | }
|
@@ -481,6 +510,7 @@ bool BLEMIDI_Client_ESP32::connect()
|
481 | 510 | {
|
482 | 511 | using namespace std::placeholders; //<- for bind funtion in callback notification
|
483 | 512 |
|
| 513 | +#ifndef BLEMIDI_FORCE_NEW_CONNECTION |
484 | 514 | /** Check if we have a client we should reuse first
|
485 | 515 | * Special case when we already know this device
|
486 | 516 | * This saves considerable time and power.
|
@@ -512,6 +542,7 @@ bool BLEMIDI_Client_ESP32::connect()
|
512 | 542 | NimBLEDevice::deleteClient(_client);
|
513 | 543 | _client = nullptr;
|
514 | 544 | }
|
| 545 | +#endif //BLEMIDI_FORCE_NEW_CONNECTION |
515 | 546 |
|
516 | 547 | if (NimBLEDevice::getClientListSize() >= NIMBLE_MAX_CONNECTIONS)
|
517 | 548 | {
|
|
0 commit comments