Skip to content

Commit eba6d8b

Browse files
committed
Update migration guide
1 parent 0e5eb9c commit eba6d8b

File tree

1 file changed

+32
-35
lines changed

1 file changed

+32
-35
lines changed

docs/Migration_guide.md

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This guide describes the required changes to existing projects migrating from th
44

55
**The changes listed here are only the required changes that must be made**, and a short overview of options for migrating existing applications.
66

7-
For more information on the improvements and additions please refer to the [class documentation](https://h2zero.github.io/NimBLE-Arduino/annotated.html) and [Improvements and updates](Improvements_and_updates.md)
7+
For more information on the improvements and additions please refer to the [class documentation](https://h2zero.github.io/esp-nimble-cpp/annotated.html) and [Improvements and updates](Improvements_and_updates.md)
88

99
* [General Changes](#general-information)
1010
* [Server](#server-api)
@@ -48,7 +48,7 @@ For example `BLEAddress addr(11:22:33:44:55:66, 1)` will create the address obje
4848

4949
As this parameter is optional no changes to existing code are needed, it is mentioned here for information.
5050

51-
`BLEAddress::getNative` (`NimBLEAddress::getNative`) returns a uint8_t pointer to the native address byte array. In this library the address bytes are stored in reverse order from the original library. This is due to the way the NimBLE stack expects addresses to be presented to it. All other functions such as `toString` are not affected as the endian change is made within them.
51+
`BLEAddress::getNative` is now named `NimBLEAddress::getBase` and returns a pointer to `const ble_addr_t` instead of a pointer to the address value.
5252
<br/>
5353

5454
<a name="server-api"></a>
@@ -72,7 +72,7 @@ void onDisconnect(NimBLEServer* pServer, NimBLEConnInfo& connInfo, int reason)`
7272
```
7373
<br/>
7474

75-
`BLEServerCallbacks::onMtuChanged` (`NimBLEServerCallbacks::onMtuChanged`) takes the parameter `NimBLEConnInfo & connInfo` instead of `esp_ble_gatts_cb_param_t`, which has methods to get information about the connected peer.
75+
`BLEServerCallbacks::onMtuChanged` is now (`NimBLEServerCallbacks::onMtuChange`) and takes the parameter `NimBLEConnInfo & connInfo` instead of `esp_ble_gatts_cb_param_t`, which has methods to get information about the connected peer.
7676

7777
```
7878
onMTUChange(uint16_t MTU, NimBLEConnInfo& connInfo)
@@ -139,6 +139,7 @@ BLECharacteristic *pCharacteristic = pService->createCharacteristic(
139139

140140
<a name="characteristic-callbacks"></a>
141141
#### Characteristic callbacks
142+
142143
`BLECharacteristicCallbacks` (`NimBLECharacteristicCallbacks`) has a new method `NimBLECharacteristicCallbacks::onSubscribe` which is called when a client subscribes to notifications/indications.
143144

144145
`BLECharacteristicCallbacks::onRead` (`NimBLECharacteristicCallbacks::onRead`) only has a single callback declaration, which takes an additional (required) parameter of `NimBLEConnInfo& connInfo`, which provides connection information about the peer.
@@ -179,8 +180,7 @@ NimBLE automatically creates the 0x2902 descriptor if a characteristic has a not
179180
It was no longer useful to have a class for the 0x2902 descriptor as a new callback `NimBLECharacteristicCallbacks::onSubscribe` was added
180181
to handle callback functionality and the client subscription status is handled internally.
181182

182-
**Note:** Attempting to create a 0x2902 descriptor will trigger an assert to notify the error,
183-
allowing the creation of it would cause a fault in the NimBLE stack.
183+
**Note:** Attempting to create a 0x2902 descriptor will trigger a warning message and flag it internally as removed and will not be functional.
184184

185185
All other descriptors are now created just as characteristics are by using the `NimBLECharacteristic::createDescriptor` method (except 0x2904, see below).
186186
Which are defined as:
@@ -208,22 +208,15 @@ pDescriptor = pCharacteristic->createDescriptor("ABCD",
208208
Would create a descriptor with the UUID 0xABCD, publicly readable but only writable if paired/bonded (encrypted) and has a max value length of 25 bytes.
209209
<br/>
210210

211-
For the 0x2904, there is a special class that is created when you call `createDescriptor("2904").
212-
213-
The pointer returned is of the base class `NimBLEDescriptor` but the call will create the derived class of `NimBLE2904` so you must cast the returned pointer to
214-
`NimBLE2904` to access the specific class methods.
215-
216-
##### Example
217-
```
218-
p2904 = (NimBLE2904*)pCharacteristic->createDescriptor("2904");
219-
```
211+
For the 0x2904, there is a specialized class that is created through `NimBLECharacteristic::create2904` which returns a pointer to a `NimBLE2904` instance which has specific
212+
functions for handling the data expect in the Characteristic Presentation Format Descriptor specification.
220213
<br/>
221214

222215
<a name="descriptor-callbacks"></a>
223216
#### Descriptor callbacks
224217

225218
> `BLEDescriptorCallbacks::onRead` (`NimBLEDescriptorCallbacks::onRead`)
226-
`BLEDescriptorCallbacks::onwrite` (`NimBLEDescriptorCallbacks::onwrite`)
219+
`BLEDescriptorCallbacks::onWrite` (`NimBLEDescriptorCallbacks::onWrite`)
227220

228221
The above descriptor callbacks take an additional (required) parameter `NimBLEConnInfo& connInfo`, which contains the connection information of the peer.
229222
<br/>
@@ -255,8 +248,7 @@ Calling `NimBLEAdvertising::setAdvertisementData` will entirely replace any data
255248

256249
> BLEAdvertising::start (NimBLEAdvertising::start)
257250
258-
Now takes 2 optional parameters, the first is the duration to advertise for (in milliseconds), the second is a callback that is invoked when advertising ends and takes a pointer to a `NimBLEAdvertising` object (similar to the `NimBLEScan::start` API).
259-
This provides an opportunity to update the advertisement data if desired.
251+
Now takes 2 optional parameters, the first is the duration to advertise for (in milliseconds), the second `NimBLEAddress` to direct advertising to a specific device.
260252
<br/>
261253

262254
<a name="client-api"></a>
@@ -268,15 +260,17 @@ Multiple client instances can be created, up to the maximum number of connection
268260

269261
`BLEClient::connect`(`NimBLEClient::connect`) Has had it's parameters altered.
270262
Defined as:
271-
> NimBLEClient::connect(bool deleteServices = true);
272-
> NimBLEClient::connect(NimBLEAdvertisedDevice\* device, bool deleteServices = true);
273-
> NimBLEClient::connect(NimBLEAddress address, bool deleteServices = true);
263+
> NimBLEClient::connect(bool deleteServices = true, , bool asyncConnect = false, bool exchangeMTU = true);
264+
> NimBLEClient::connect(const NimBLEAddress& address, bool deleteAttributes = true, bool asyncConnect = false, bool exchangeMTU = true);
265+
> NimBLEClient::connect(const NimBLEAdvertisedDevice* device, bool deleteServices = true, bool asyncConnect = false, bool exchangeMTU = true);
274266
275267
The type parameter has been removed and a new bool parameter has been added to indicate if the client should delete the attribute database previously retrieved (if applicable) for the peripheral, default value is true.
276268

277-
If set to false the client will use the attribute database it retrieved from the peripheral when previously connected.
269+
If set to false the client will use the attribute database it retrieved from the peripheral when previously connected. This allows for faster connections and power saving if the devices dropped connection and are reconnecting.
278270

279-
This allows for faster connections and power saving if the devices dropped connection and are reconnecting.
271+
The parameter `bool asyncConnect` if true, will cause the client to send the connect command to the stack and return immediately without blocking. The return value will represent wether the command was sent successfully or not and the `NimBLEClientCallbacks::onConnect` or `NimBLEClientCallbacks::onConnectFail` will be called when the operation is complete.
272+
273+
The parameter `bool exchangeMTU` if true, will cause the client to perform the exchange MTU process upon connecting. If false the MTU exchange will need to be performed by the application by calling `NimBLEClient::exchangeMTU`. If the connection is only sending small payloads it may be advantageous to not exchange the MTU to gain performance in the connection process.
280274
<br/>
281275

282276
> `BLEClient::getServices` (`NimBLEClient::getServices`)
@@ -301,8 +295,7 @@ This method has been removed.
301295

302296
> `BLERemoteService::getCharacteristics` (`NimBLERemoteService::getCharacteristics`)
303297
304-
This method now takes an optional (bool) parameter to indicate if the characteristics should be retrieved from the server (true) or
305-
the currently known database returned (false : default).
298+
This method now takes an optional (bool) parameter to indicate if the characteristics should be retrieved from the server (true) or the currently known database returned, default = false.
306299
Also now returns a pointer to `std::vector` instead of `std::map`.
307300
<br/>
308301

@@ -326,23 +319,23 @@ Has been removed.
326319
Are the new methods added to replace it.
327320
<br/>
328321

329-
> `BLERemoteCharacteristic::readUInt8` (`NimBLERemoteCharacteristic::readUInt8`)
330-
> `BLERemoteCharacteristic::readUInt16` (`NimBLERemoteCharacteristic::readUInt16`)
331-
> `BLERemoteCharacteristic::readUInt32` (`NimBLERemoteCharacteristic::readUInt32`)
322+
> `BLERemoteCharacteristic::readUInt8` (`NimBLERemoteCharacteristic::readUInt8`)
323+
> `BLERemoteCharacteristic::readUInt16` (`NimBLERemoteCharacteristic::readUInt16`)
324+
> `BLERemoteCharacteristic::readUInt32` (`NimBLERemoteCharacteristic::readUInt32`)
332325
> `BLERemoteCharacteristic::readFloat` (`NimBLERemoteCharacteristic::readFloat`)
333326
334-
Are **deprecated** a template: `NimBLERemoteCharacteristic::readValue<type\>(time_t\*, bool)` has been added to replace them.
327+
Are **removed** a template: `NimBLERemoteCharacteristic::readValue<type\>(time_t\*, bool)` has been added to replace them.
335328
<br/>
336329

337330
> `BLERemoteCharacteristic::readRawData`
338331
339332
**Has been removed from the API**
340333
Originally it stored an unnecessary copy of the data and was returning a `uint8_t` pointer to volatile internal data.
341334
The user application should use `NimBLERemoteCharacteristic::readValue` or `NimBLERemoteCharacteristic::getValue`.
342-
To obtain a copy of the data, then cast the returned std::string to the type required such as:
335+
To obtain a copy of the data as a `NimBLEAttValue` instance and use the `NimBLEAttValue::data` member function to obtain the pointer.
343336
```
344-
std::string value = pChr->readValue();
345-
uint8_t *data = (uint8_t*)value.data();
337+
NimBLEAttValue value = pChr->readValue();
338+
const uint8_t *data = value.data();
346339
```
347340
Alternatively use the `readValue` template:
348341
```
@@ -352,8 +345,7 @@ my_struct_t myStruct = pChr->readValue<my_struct_t>();
352345

353346
> `BLERemoteCharacteristic::getDescriptors` (`NimBLERemoteCharacteristic::getDescriptors`)
354347
355-
This method now takes an optional (bool) parameter to indicate if the descriptors should be retrieved from the server (true) or
356-
the currently known database returned (false : default).
348+
This method now takes an optional (bool) parameter to indicate if the descriptors should be retrieved from the server (true) or the currently known database returned, default = false.
357349
Also now returns a pointer to `std::vector` instead of `std::map`.
358350
<br/>
359351

@@ -373,7 +365,12 @@ The default configuration will use "just-works" pairing with no bonding, if you
373365

374366
<a name="scan-api"></a>
375367
## BLE Scan
376-
The scan API is mostly unchanged from the original except for `NimBLEScan::start`, in which the duration parameter is now in milliseconds instead of seconds.
368+
The scan API is mostly unchanged from the original except for `NimBLEScan::start`, which has the following changes:
369+
* The duration parameter is now in milliseconds instead of seconds.
370+
* The callback parameter has been removed.
371+
* A new parameter `bool restart` has been added, when set to true to restart the scan if already in progress and clear the duplicate cache.
372+
373+
The blocking overload of `NimBLEScan::start` has been replaced by an overload of `NimBLEScan::getResults` with the same parameters.
377374
<br/>
378375

379376
<a name="security-api"></a>
@@ -386,7 +383,7 @@ The callback methods are:
386383
> `bool onConfirmPasskey(NimBLEConnInfo& connInfo, uint32_t pin)`
387384
388385
Receives the pin when using numeric comparison authentication.
389-
Call `NimBLEDevice::injectConfirmPIN(connInfo, true);` to accept or `NimBLEDevice::injectConfirmPIN(connInfo, false);` to reject.
386+
Call `NimBLEDevice::injectConfirmPasskey(connInfo, true);` to accept or `NimBLEDevice::injectConfirmPasskey(connInfo, false);` to reject.
390387
<br/>
391388

392389
> `void onPassKeyEntry(NimBLEConnInfo& connInfo)`

0 commit comments

Comments
 (0)