@@ -10,7 +10,62 @@ BEGIN_BLEMIDI_NAMESPACE
1010// Dependanced class settings
1111struct BLEDefaultSettings : public CommonBLEDefaultSettings
1212{
13- // TODO Create parametric configurations
13+
14+ /*
15+ ###### TX POWER #####
16+ */
17+
18+ /* *
19+ * Set power transmision
20+ */
21+ static const uint8_t BLETXPwr = 9 ; // in dBm
22+
23+ /*
24+ ###### SECURITY #####
25+ */
26+
27+ /* * Set the IO capabilities of the device, each option will trigger a different pairing method.
28+ * * 0x00 BLE_HS_IO_DISPLAY_ONLY DisplayOnly IO capability
29+ * * 0x01 BLE_HS_IO_DISPLAY_YESNO DisplayYesNo IO capability
30+ * * 0x02 BLE_HS_IO_KEYBOARD_ONLY KeyboardOnly IO capability
31+ * * 0x03 BLE_HS_IO_NO_INPUT_OUTPUT NoInputNoOutput IO capability
32+ * * 0x04 BLE_HS_IO_KEYBOARD_DISPLAY KeyboardDisplay Only IO capability
33+ */
34+ static const uint8_t BLESecurityCapabilities = BLE_HS_IO_NO_INPUT_OUTPUT;
35+
36+ /* * Set the security method.
37+ * bonding
38+ * man in the middle protection
39+ * pair. secure connections
40+ *
41+ * More info in nimBLE lib
42+ */
43+ static const bool BLEBond = true ;
44+ static const bool BLEMITM = false ;
45+ static const bool BLEPair = true ;
46+
47+ /*
48+ ###### BLE COMMUNICATION PARAMS ######
49+ */
50+
51+ /* * Set connection parameters:
52+ * If you only use one connection, put recomended BLE server param communication
53+ * (you may scan it ussing "nRF Connect" app or other similar apps).
54+ *
55+ * If you use more than one connection adjust, for example, settings like 15ms interval, 0 latency, 120ms timout.
56+ * These settings may be safe for 3 clients to connect reliably, set faster values if you have less
57+ * connections.
58+ *
59+ * Min interval (unit: 1.25ms): 12 * 1.25ms = 15 ms,
60+ * Max interval (unit: 1.25ms): 12 * 1.25ms = 15,
61+ * 0 latency (Number of intervals allowed to skip),
62+ * TimeOut (unit: 10ms) 51 * 10ms = 510ms. Timeout should be minimum 100ms.
63+ */
64+ static const uint16_t commMinInterval = 6 ; // 7.5ms
65+ static const uint16_t commMaxInterval = 35 ; // 40ms
66+ static const uint16_t commLatency = 0 ; //
67+ static const uint16_t commTimeOut = 200 ; // 2000ms
68+
1469};
1570
1671template <class _Settings >
@@ -90,13 +145,13 @@ class MyServerCallbacks : public BLEServerCallbacks
90145protected:
91146 BLEMIDI_ESP32_NimBLE<_Settings> *_bluetoothEsp32 = nullptr ;
92147
93- void onConnect (BLEServer *)
148+ void onConnect (BLEServer *, NimBLEConnInfo & )
94149 {
95150 if (_bluetoothEsp32)
96151 _bluetoothEsp32->connected ();
97152 };
98153
99- void onDisconnect (BLEServer *)
154+ void onDisconnect (BLEServer *, NimBLEConnInfo & )
100155 {
101156 if (_bluetoothEsp32)
102157 _bluetoothEsp32->disconnected ();
@@ -115,7 +170,7 @@ class MyCharacteristicCallbacks : public BLECharacteristicCallbacks
115170protected:
116171 BLEMIDI_ESP32_NimBLE<_Settings> *_bluetoothEsp32 = nullptr ;
117172
118- void onWrite (BLECharacteristic *characteristic)
173+ void onWrite (BLECharacteristic *characteristic, NimBLEConnInfo & )
119174 {
120175 std::string rxValue = characteristic->getValue ();
121176 if (rxValue.length () > 0 )
@@ -131,27 +186,11 @@ bool BLEMIDI_ESP32_NimBLE<_Settings>::begin(const char *deviceName, BLEMIDI_Tran
131186 _bleMidiTransport = bleMidiTransport;
132187
133188 BLEDevice::init (deviceName);
189+
190+ NimBLEDevice::setSecurityIOCap (_Settings::BLESecurityCapabilities); // Attention, it may need a passkey
191+ NimBLEDevice::setSecurityAuth (_Settings::BLEBond, _Settings::BLEMITM, _Settings::BLEPair);
134192
135- /* *
136- * Set the IO capabilities of the device, each option will trigger a different pairing method.
137- * BLE_HS_IO_DISPLAY_ONLY - Passkey pairing
138- * BLE_HS_IO_DISPLAY_YESNO - Numeric comparison pairing
139- * BLE_HS_IO_NO_INPUT_OUTPUT - DEFAULT setting - just works pairing
140- */
141- // NimBLEDevice::setSecurityIOCap(BLE_HS_IO_DISPLAY_ONLY); // use passkey
142- // NimBLEDevice::setSecurityIOCap(BLE_HS_IO_DISPLAY_YESNO); //use numeric comparison
143-
144- /* *
145- * 2 different ways to set security - both calls achieve the same result.
146- * no bonding, no man in the middle protection, BLE secure connections.
147- *
148- * These are the default values, only shown here for demonstration.
149- */
150- // NimBLEDevice::setSecurityAuth(false, false, true);
151-
152- // NimBLEDevice::setSecurityAuth(/*BLE_SM_PAIR_AUTHREQ_BOND | BLE_SM_PAIR_AUTHREQ_MITM |*/ BLE_SM_PAIR_AUTHREQ_SC);
153-
154- NimBLEDevice::setSecurityAuth (true , false , false );
193+ /* * Optional: set the transmit power, default is 3db */ NimBLEDevice::setPower (_Settings::BLETXPwr); /* * +9db */
155194
156195 // To communicate between the 2 cores.
157196 // Core_0 runs here, core_1 runs the BLE stack
@@ -166,17 +205,21 @@ bool BLEMIDI_ESP32_NimBLE<_Settings>::begin(const char *deviceName, BLEMIDI_Tran
166205
167206 // Create a BLE Characteristic
168207 _characteristic = service->createCharacteristic (
169- BLEUUID (CHARACTERISTIC_UUID),
170- NIMBLE_PROPERTY::READ |
208+ BLEUUID (CHARACTERISTIC_UUID),
209+ NIMBLE_PROPERTY::READ |
171210 NIMBLE_PROPERTY::WRITE |
172211 NIMBLE_PROPERTY::NOTIFY |
173212 NIMBLE_PROPERTY::WRITE_NR);
174213
175214 _characteristic->setCallbacks (new MyCharacteristicCallbacks<_Settings>(this ));
176215
177216
178- NimBLEDevice::setSecurityIOCap (BLE_HS_IO_NO_INPUT_OUTPUT); // Attention
179-
217+ NimBLEDevice::setSecurityIOCap (_Settings::BLESecurityCapabilities); // Attention, it may need a passkey
218+ NimBLEDevice::setSecurityAuth (_Settings::BLEBond, _Settings::BLEMITM, _Settings::BLEPair);
219+
220+ /* * Optional: set the transmit power, default is 3db */
221+ NimBLEDevice::setPower (_Settings::BLETXPwr); /* * +9db */
222+
180223
181224 // Start the service
182225 service->start ();
0 commit comments