Skip to content

Commit 2e4b39f

Browse files
committed
replaced NimBLESecurity with NimBLEDevice::setSecurityAuth
1 parent f0c3581 commit 2e4b39f

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/hardware/BLEMIDI_ESP32.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include <BLEServer.h>
77
#include <BLE2902.h>
88

9+
// Note: error: redefinition of 'class BLEDescriptor' is a namespace collision on class BLEDescriptor between our ESp32 BLE and ArduinoBLE
10+
// Solution: remove ArduinoBLE
11+
912
BEGIN_BLEMIDI_NAMESPACE
1013

1114
class BLEMIDI_ESP32
@@ -113,7 +116,7 @@ class MyCharacteristicCallbacks : public BLECharacteristicCallbacks
113116

114117
void onWrite(BLECharacteristic *characteristic)
115118
{
116-
std::string rxValue = characteristic->getValue();
119+
auto rxValue = characteristic->getValue();
117120
if (rxValue.length() > 0)
118121
{
119122
_bluetoothEsp32->receive((uint8_t *)(rxValue.c_str()), rxValue.length());

src/hardware/BLEMIDI_ESP32_NimBLE.h

+21-3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,27 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport<class
120120

121121
BLEDevice::init(deviceName);
122122

123+
/**
124+
* Set the IO capabilities of the device, each option will trigger a different pairing method.
125+
* BLE_HS_IO_DISPLAY_ONLY - Passkey pairing
126+
* BLE_HS_IO_DISPLAY_YESNO - Numeric comparison pairing
127+
* BLE_HS_IO_NO_INPUT_OUTPUT - DEFAULT setting - just works pairing
128+
*/
129+
// NimBLEDevice::setSecurityIOCap(BLE_HS_IO_DISPLAY_ONLY); // use passkey
130+
// NimBLEDevice::setSecurityIOCap(BLE_HS_IO_DISPLAY_YESNO); //use numeric comparison
131+
132+
/**
133+
* 2 different ways to set security - both calls achieve the same result.
134+
* no bonding, no man in the middle protection, BLE secure connections.
135+
*
136+
* These are the default values, only shown here for demonstration.
137+
*/
138+
// NimBLEDevice::setSecurityAuth(false, false, true);
139+
140+
// NimBLEDevice::setSecurityAuth(/*BLE_SM_PAIR_AUTHREQ_BOND | BLE_SM_PAIR_AUTHREQ_MITM |*/ BLE_SM_PAIR_AUTHREQ_SC);
141+
142+
NimBLEDevice::setSecurityAuth(true, false, false);
143+
123144
// To communicate between the 2 cores.
124145
// Core_0 runs here, core_1 runs the BLE stack
125146
mRxQueue = xQueueCreate(64, sizeof(uint8_t)); // TODO Settings::MaxBufferSize
@@ -141,9 +162,6 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport<class
141162

142163
_characteristic->setCallbacks(new MyCharacteristicCallbacks(this));
143164

144-
auto _security = new NimBLESecurity();
145-
_security->setAuthenticationMode(ESP_LE_AUTH_BOND);
146-
147165
// Start the service
148166
service->start();
149167

0 commit comments

Comments
 (0)