Skip to content

Commit 4980e6a

Browse files
committed
[BREAKING] - Refactor NimBLEAdvertising
* General code cleanup. * `NimBLEAdvertisementData` moved to it's own .h and .cpp files. * Added new method, `NimBLEAdvertising::setPreferredParams` that takes the min and max preferred connection parameters as an alternative for `setMinPreferred` and `setMaxPreferred`. * Added new method, `NimBLEAdvertising::setAdvertisingInterval` Sets the advertisement interval for min and max to the same value instead of calling `setMinInterval` and `setMaxInterval` separately if there is not value difference. * `NimBLEAdvertisementData` payload is now stored in `std::vector<uint8_t>` instead of `std::string`. * `NimBLEAdvertisementData::getPayload` now returns `std::vector<uint8_t>` instead of `std::string`. * `NimBLEAdvertisementData::addData` now takes either a `std::vector<uint8_t>` or `uint8_t* + length` instead of `std::string` or `char + length`. * `NimBLEAdvertisementData::setName` now takes an optional `bool` parameter to indicate if the name is complete or incomplete, default = complete. * `NimBLEAdvertising::start` No longer takes a callback pointer parameter, instead the new method `NimBLEAdvertising::setAdvertisingCompleteCallback` should be used. * `NimBLEAdvertising::setAdvertisementType` has been renamed to `NimBLEAdvertising::setConnectableMode` to better reflect it's function. * `NimBLEAdvertising::setScanResponse` has been renamed to `NimBLEAdvertising::enableScanResponse` to better reflect it's function. * Scan response is no longer enabled by default. * Added new method, `NimBLEAdvertising::setDiscoverableMode` to allow applications to control the discoverability of the advertiser. * Advertising the name and TX power of the device will no longer happen by default and should be set manually by the application. * Added overload for `NimBLEAdvertising::setManufacturerData` that takes a `const uint8_t*` and , size_t` paramter. * Added overload for `NimBLEAdvertising::setServiceData` that takes `const NimBLEUUID& uuid`, ` const uint8_t* data`, ` size_t length` as parameters. * Added overload for `NimBLEAdvertising::setServiceData` that takes `const NimBLEUUID& uuid`, `const std::vector<uint8_t>&` as parameters. * All `NimBLEAdvertisementData` functions that change data values now return `bool`, true = success. * All `NimBLEAdvertising` functions that change data values now return `bool`, true = success. * `NimBLEAdvertising::setMinPreferred` and `NimBLEAdvertising::setMaxPreferred` have been removed, use `NimBLEAdvertising::setPreferredParams` instead. * All advertising data is now stored in instances of `NimBLEAdvertisingData` and vectors removed from `NimBLEAdvertising`. * `NimBLEAdvertising::setAdvertisementData` and `NimBLEAdvertising::setScanResponseData` now return `bool`, true = success. * Added new method, `NimBLEAdvertisementData::removeData`, which takes a parameter `uint8_t type`, the data type to remove. * Added new method, `NimBLEAdvertisementData::toString`, which will print the data in hex. * Added new method, `NimBLEAdvertising::getAdvertisementData`, which returns a reference to the currently set advertisement data. * Added new method, `NimBLEAdvertising::getScanData`, which returns a reference to the currently set scan response data. * Added overloads for `NimBLEAdvertising::removeServiceUUID` and `NimBLEAdvertisementData::removeServiceUUID` to accept a `const char*` * Added new method, `NimBLEAdvertising::clearData`, which will clear the advertisement and scan response data.
1 parent 5229139 commit 4980e6a

File tree

9 files changed

+1082
-935
lines changed

9 files changed

+1082
-935
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ idf_component_register(
4444
"src/NimBLE2904.cpp"
4545
"src/NimBLEAddress.cpp"
4646
"src/NimBLEAdvertisedDevice.cpp"
47+
"src/NimBLEAdvertisementData.cpp"
4748
"src/NimBLEAdvertising.cpp"
4849
"src/NimBLEAttValue.cpp"
4950
"src/NimBLEBeacon.cpp"

examples/Advanced/NimBLE_Server/main/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void app_main(void) {
233233
/** If your device is battery powered you may consider setting scan response
234234
* to false as it will extend battery life at the expense of less data sent.
235235
*/
236-
pAdvertising->setScanResponse(true);
236+
pAdvertising->enableScanResponse(true);
237237
pAdvertising->start();
238238

239239
printf("Advertising Started\n");

examples/NimBLE_server_get_client_name/main/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ extern "C" void app_main(void) {
6060

6161
BLEAdvertising* pAdvertising = NimBLEDevice::getAdvertising();
6262
pAdvertising->addServiceUUID(SERVICE_UUID);
63-
pAdvertising->setScanResponse(true);
63+
pAdvertising->enableScanResponse(true);
6464

6565
pAdvertising->start();
6666
printf("Advertising started, connect with your phone.\n");

examples/basic/BLE_notify/main/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void app_main(void) {
152152
// Start advertising
153153
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
154154
pAdvertising->addServiceUUID(SERVICE_UUID);
155-
pAdvertising->setScanResponse(false);
155+
pAdvertising->enableScanResponse(false);
156156
/** This method had been removed **
157157
pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter
158158
**/

examples/basic/BLE_server/main/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,27 @@ void app_main(void) {
3131
BLEService *pService = pServer->createService(SERVICE_UUID);
3232
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
3333
CHARACTERISTIC_UUID,
34-
/***** Enum Type NIMBLE_PROPERTY now *****
34+
/***** Enum Type NIMBLE_PROPERTY now *****
3535
BLECharacteristic::PROPERTY_READ |
36-
BLECharacteristic::PROPERTY_WRITE
36+
BLECharacteristic::PROPERTY_WRITE
3737
);
3838
*****************************************/
3939
NIMBLE_PROPERTY::READ |
40-
NIMBLE_PROPERTY::WRITE
40+
NIMBLE_PROPERTY::WRITE
4141
);
4242

4343
pCharacteristic->setValue("Hello World says Neil");
4444
pService->start();
4545
// BLEAdvertising *pAdvertising = pServer->getAdvertising(); // this still is working for backward compatibility
4646
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
4747
pAdvertising->addServiceUUID(SERVICE_UUID);
48-
pAdvertising->setScanResponse(true);
49-
48+
pAdvertising->enableScanResponse(true);
49+
5050
/** These methods have been removed **
5151
pAdvertising->setMinPreferred(0x06); // functions that help with iPhone connections issue
5252
pAdvertising->setMinPreferred(0x12);
5353
*/
54-
54+
5555
BLEDevice::startAdvertising();
5656
printf("Characteristic defined! Now you can read it in your phone!\n");
5757
}

0 commit comments

Comments
 (0)