@@ -96,7 +96,7 @@ static uint32_t userOnPassKeyRequest()
96
96
return passkey;
97
97
};
98
98
99
- /*
99
+ /*
100
100
###### BLE COMMUNICATION PARAMS ######
101
101
*/
102
102
/* * Set connection parameters:
@@ -117,6 +117,23 @@ static uint32_t userOnPassKeyRequest()
117
117
#define BLEMIDI_CLIENT_COMM_LATENCY 0 //
118
118
#define BLEMIDI_CLIENT_COMM_TIMEOUT 200 // 2000ms
119
119
120
+ /*
121
+ ###### BLE FORCE NEW CONNECTION ######
122
+ */
123
+
124
+ /* *
125
+ * This parameter force to skip the "soft-reconnection" and force to create a new connection after a disconnect event.
126
+ * "Soft-reconnection" save some time and energy in comparation with performming a new connection, but some BLE devices
127
+ * don't support or don't perform correctly a "soft-reconnection" after a disconnection event.
128
+ * Uncomment this define if your device doesn't work propertily after a reconnection.
129
+ *
130
+ */
131
+ #define BLEMIDI_FORCE_NEW_CONNECTION
132
+
133
+ /* *
134
+ *
135
+ */
136
+
120
137
/*
121
138
#############################################
122
139
############ USER DEFINES END ###############
@@ -340,6 +357,13 @@ class MyClientCallbacks : public BLEClientCallbacks
340
357
_bluetoothEsp32->disconnected ();
341
358
}
342
359
360
+ #ifdef BLEMIDI_FORCE_NEW_CONNECTION
361
+ // Renew Client
362
+ NimBLEDevice::deleteClient (pClient);
363
+ // NimBLEDevice::createClient();
364
+ pClient = nullptr ;
365
+ #endif // BLEMIDI_FORCE_NEW_CONNECTION
366
+
343
367
// Try reconnection or search a new one
344
368
NimBLEDevice::getScan ()->start (1 , scanEndedCB);
345
369
}
@@ -481,6 +505,7 @@ bool BLEMIDI_Client_ESP32::connect()
481
505
{
482
506
using namespace std ::placeholders; // <- for bind funtion in callback notification
483
507
508
+ #ifndef BLEMIDI_FORCE_NEW_CONNECTION
484
509
/* * Check if we have a client we should reuse first
485
510
* Special case when we already know this device
486
511
* This saves considerable time and power.
@@ -512,6 +537,7 @@ bool BLEMIDI_Client_ESP32::connect()
512
537
NimBLEDevice::deleteClient (_client);
513
538
_client = nullptr ;
514
539
}
540
+ #endif // BLEMIDI_FORCE_NEW_CONNECTION
515
541
516
542
if (NimBLEDevice::getClientListSize () >= NIMBLE_MAX_CONNECTIONS)
517
543
{
0 commit comments