Skip to content

Commit def06b1

Browse files
authored
Merge pull request #48 from RobertoHE/master
Disable Soft-Reconnection, thank you @RobertoHE !
2 parents 5c42e14 + ebe18da commit def06b1

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/hardware/BLEMIDI_Client_ESP32.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
*
7676
* Uncomment what you need
7777
* These are the default values.
78+
* You can select some simultaneously.
7879
*/
7980
#define BLEMIDI_CLIENT_BOND
8081
//#define BLEMIDI_CLIENT_MITM
@@ -86,7 +87,7 @@
8687
*/
8788
static uint32_t userOnPassKeyRequest()
8889
{
89-
//FILL WITH YOUR CUSTOM AUTH METHOD or PASSKEY
90+
//FILL WITH YOUR CUSTOM AUTH METHOD CODE or PASSKEY
9091
//FOR EXAMPLE:
9192
uint32_t passkey = 123456;
9293

@@ -117,6 +118,23 @@ static uint32_t userOnPassKeyRequest()
117118
#define BLEMIDI_CLIENT_COMM_LATENCY 0 //
118119
#define BLEMIDI_CLIENT_COMM_TIMEOUT 200 //2000ms
119120

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+
120138
/*
121139
#############################################
122140
############ USER DEFINES END ###############
@@ -338,8 +356,19 @@ class MyClientCallbacks : public BLEClientCallbacks
338356
if (_bluetoothEsp32)
339357
{
340358
_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
341363
}
342364

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+
343372
//Try reconnection or search a new one
344373
NimBLEDevice::getScan()->start(1, scanEndedCB);
345374
}
@@ -481,6 +510,7 @@ bool BLEMIDI_Client_ESP32::connect()
481510
{
482511
using namespace std::placeholders; //<- for bind funtion in callback notification
483512

513+
#ifndef BLEMIDI_FORCE_NEW_CONNECTION
484514
/** Check if we have a client we should reuse first
485515
* Special case when we already know this device
486516
* This saves considerable time and power.
@@ -512,6 +542,7 @@ bool BLEMIDI_Client_ESP32::connect()
512542
NimBLEDevice::deleteClient(_client);
513543
_client = nullptr;
514544
}
545+
#endif //BLEMIDI_FORCE_NEW_CONNECTION
515546

516547
if (NimBLEDevice::getClientListSize() >= NIMBLE_MAX_CONNECTIONS)
517548
{

0 commit comments

Comments
 (0)