2.0.0
Finally! A new release with something more than a bugfix or some minor additions!
I'm excited to present this release properly after the unfortunate Arduino Library Manager debacle 🎉.
This was a complete overhaul of the codebase, every file as been touched up and some completely re-designed, removed, added, or changed significantly. This required A LOT of changes, many will break your current application code, but don't worry, it will be much better!
This release has so much in it!
Highlights
- Reduced the code size by over 40KB.
- Significant reduction in memory use.
- Huge performance boost.
- Asynchronous client connect, MTU exchange, and secure connection options to speed up the connecting process.
- Asynchronous passkey entry/confirmation so the client/server can have time to properly display/enter the passkey before action is performed.
- Scan restart option to clear the duplicate cache so the same devices will be found again.
- New scan callbacks class with extra functions that will get called on first discovery, before and scan response data is received.
- Ability to update advertised data while advertising.
- Improved support for dynamically changing services/characteristics/descriptors.
- Simplified code for easier maintenance and understanding for contributors.
Full Changelog
Breaking changes
- All connection oriented callbacks now receive a reference to
NimBLEConnInfo, theble_gap_conn_deschas also been replace withNimBLEConnInfoin the functions that received it. - All functions that take a time input parameter now expect the value to be in milliseconds instead of seconds.
- Removed Eddystone URL as it has been shutdown by google since 2021.
- NimBLESecurity class removed.
NimBLEDeviceIgnore list functions removed.NimBLEDevice::startSecuritynow returns abool, true on success, instead of an int to be consistent with the rest of the library.NimBLEDevice::getInitializedrenamed toNimBLEDevice::isInitialized.NimBLEDevice::setPowerno longer takes theesp_power_level_tandesp_ble_power_type_t, instead only an integer value in dbm units is accepted.NimBLEDevice::setOwnAddrTypeno longer takes abool nrpaparameter.NimBLEDevice::getClientListSizereplaced withNimBLEDevice::getCreatedClientCount.NimBLEDevice::getClientListwas removed.NimBLEServer::disconnectnow returnsbool, true = success, instead ofintto be consistent with the rest of the library.NimBLEServerCallbacks::onMTUChangedrenamed toNimBLEServerCallbacks::onMTUChangeto be consistent with the client callback.NimBLEServer::getPeerIDInforenamed toNimBLEServer::getPeerInfoByHandleto better describe it's use.NimBLEServerCallbacks::onPassKeyRequesthas been replaced withNimBLEServer::onPassKeyDisplaywhich should display the pairing pin that the client is expected to send.NimBLEServerCallbacks::onAuthenticationCompletenow takes aNimBLEConnInfo¶meter.NimBLEClient::getServicesnow returns a const reference to std::vector<NimBLERemoteService*> instead of a pointer to the internal vector.NimBLEClient::getConnIdhas been renamed togetConnHandleto be consistent with bluetooth terminology.NimBLEClient::disconnectnow returns abool, true on success, instead of an int to be consistent with the rest of the library.NimBLEClientCallbacks::onDisconnectnow takes an additionalint reasonparameter to let the application know why the disconnect occurred.NimBLEClientCallbacks::onPassKeyRequesthas been changed toNimBLEClientCallbacks::onPassKeyEntrywhich takes aNimBLEConnInfo¶meter and does not return a value. Instead or returning a value this callback should prompt a user to enter a pin number which is sent later viaNimBLEDevice::injectPassKey.NimBLEClientCallbacks::onConfirmPINrenamed toNimBLEClientCallbacks::onConfirmPasskeyand no longer returns a value and now takes aNimBLEConnInfo¶meter. This should be used to prompt a user to confirm the pin on the display (YES/NO) after which the response should be sent withNimBLEDevice::injectConfirmPasskey.NimBLEAdvertising::setMinPreferredandNimBLEAdvertising::setMaxPreferredhave been removed, useNimBLEAdvertising::setPreferredParamsinstead.- Advertising the name and TX power of the device will no longer happen by default and should be set manually by the application.
NimBLEAdvertising::setAdvertisementTypehas been renamed toNimBLEAdvertising::setConnectableModeto better reflect it's function.NimBLEAdvertising::setScanResponsehas been renamed toNimBLEAdvertising::enableScanResponseto better reflect it's function.NimBLEAdvertising; Scan response is no longer enabled by default.NimBLEAdvertising::startNo longer takes a callback pointer parameter, instead the new methodNimBLEAdvertising::setAdvertisingCompleteCallbackshould be used.NimBLEAdvertisementData::addDatanow takes either astd::vector<uint8_t>oruint8_t* + lengthinstead ofstd::stringorchar + length.NimBLEAdvertisementData::getPayloadnow returnsstd::vector<uint8_t>instead ofstd::string.- The callback parameter for
NimBLEScan::starthas been removed and the blocking overload ofNimBLEScan::starthas been replaced by an overload ofNimBLEScan::getResultswith the same parameters. NimBLEAdvertisedDeviceCallbacksHas been replaced byNimBLEScanCallbackswhich contains the following methods:onResult,onScanEnd, and `onDiscovered-
NimBLEScanCallbacks::onResult, functions the same as the oldNimBLEAdvertisedDeviceCallbacks::onResultbut now takes aaconst NimBLEAdvertisedDevice*instead of non-const.
-
NimBLEScanCallbacks::onScanEnd, replaces the scanEnded callback passed toNimBLEScan::startand now takes aconst NimBLEScanResults&andint reasonparameter.
-
NimBLEScanCallbacks::onDiscovered, This is called immediately when a device is first scanned, before any scan response data is available and takes aconst NimBLEAdvertisedDevice*parameter.
NimBLEScan::stopwill no longer call theonScanEndcallback as the caller should know its been stopped when this is called.NimBLEScan::clearDuplicateCachehas been removed as it was problematic and only for the esp32. Stop and start the scanner for the same effect.NimBLEScanResults::getDevicemethods now returnconst NimBLEAdvertisedDevice*.NimBLEScanResultsiterators are nowconst_iterator.NimBLEAdvertisedDevice::hasRSSIremoved as redundant, RSSI is always available.NimBLEAdvertisedDevice::getPayloadnow returnsconst std::vector<uint8_t>instead of a pointer to internal memory.NimBLEAdvertisedDeviceTimestamp removed, if needed then the app should track the time from the callback.NimBLECharacteristic::notifyno longer takes abool is_notificationparameter, insteadindicate()should be called to send indications.NimBLECharacteristicCallbacks::onNotifyremoved as unnecessary, the library does not call notify without app input.NimBLECharacteristicCallbacks::onStatusNo longer takes astatusparameter, refer to the return code for success/failure.NimBLERemoteCharacteristic::getRemoteServicenow returns aconst NimBLERemoteService*instead of non-const.NimBLERemoteCharacteristic::readUInt32Has been removed.NimBLERemoteCharacteristic::readUInt16Has been removed.NimBLERemoteCharacteristic::readUInt8Has been removed.NimBLERemoteCharacteristic::readFloatHas been removed.NimBLERemoteCharacteristic::registerForNotifyHas been removed.NimBLERemoteService::getCharacteristicsnow returns aconst std::vector<NimBLERemoteCharacteristic*>&instead of non-conststd::vector<NimBLERemoteCharacteristic*>*.NimBLERemoteService::getValuenow returnsNimBLEAttValueinstead ofstd::string.NimBLEService::getCharacteristicsnow returns aconst std::vector<NimBLECharacteristic*>&instead of std::vector<NimBLECharacteristic *>.NimBLEUUID::getNativemethod replaced withNimBLEUUID::getBasewhich returns a read-only pointer to the underlyingble_uuid_tstruct.NimBLEUUID;msbFirstparameter has been removed from constructor, caller should reverse the data first or call the newreverseByteOrdermethod after.NimBLEAddressconstructor; default value for thetypeparameter removed, caller should know the address type and specify it.NimBLEAddress::getNativereplaced withNimBLEAddress::getBaseand now returns a pointer toconst ble_addr_tinstead of a pointer to the address value.NimBLEAddress::equalsmethod andNimBLEAddress::== operatorwill now also test if the address types are the same.NimBLEUtils::dumpGapEventfunction removed.NimBLEUtils::buildHexDatareplaced withNimBLEUtils::dataToHexString, which returns astd::stringcontaining the hex string.NimBLEEddystoneTLM::setTempnow takes anint16_tparameter instead of float to be friendly to devices without floating point support.NimBLEEddystoneTLM::getTempnow returnsint16_tto work with devices that don't have floating point support.NimBLEEddystoneTLM::setDatanow takes a reference to *NimBLEEddystoneTLM::BeaconDatainstead ofstd::string.NimBLEEddystoneTLM::getDatanow returns a reference to *NimBLEEddystoneTLM::BeaconDatainstead ofstd::string.NimBLEBeacon::setDatanow takesconst NimBLEBeacon::BeaconData&instead ofstd::string.NimBLEBeacon::getDatanow returnsconst NimBLEBeacon::BeaconData&instead ofstd::string.NimBLEHIDDevice::reportMaprenamed toNimBLEHIDDevice::getReportMap.NimBLEHIDDevice::hidControlrenamed toNimBLEHIDDevice::getHidControl.NimBLEHIDDevice::inputReportrenamed toNimBLEHIDDevice::getInputReport.NimBLEHIDDevice::outputReportrenamed toNimBLEHIDDevice::getOutputReport.NimBLEHIDDevice::featureReportrenamed toNimBLEHIDDevice::getFeatureReport.NimBLEHIDDevice::protocolModerenamed toNimBLEHIDDevice::getProtocolMode.NimBLEHIDDevice::bootOutputrenamed toNimBLEHIDDevice::getBootOutput.NimBLEHIDDevice::pnprenamed toNimBLEHIDDevice::setPnp.NimBLEHIDDevice::hidInforenamed toNimBLEHIDDevice::setHidInfo.NimBLEHIDDevice::deviceInforenamed toNimBLEHIDDevice::getDeviceInfoService.NimBLEHIDDevice::hidServicerenamed toNimBLEHIDDevice::getHidService.NimBLEHIDDevice::batteryServicerenamed toNimBLEHIDDevice::getBatteryService.
Fixed
NimBLEDevice::getPowerandNimBLEDevice::getPowerLevelbug worked around for the esp32s3 and esp32c3.NimBLEDevice::setPowerandNimBLEDevice::getPowernow support the full power range for all esp devices.NimBLEDevice::setOwnAddrTypewill now correctly apply the provided address type for all devices.NimBLEDevice::getPower(esp32) return value is now calculated to support devices with different min/max ranges.- Crash if
NimBLEDevice::deinitis called when the stack has not been initialized. NimBLEServerservice changed notifications will now wait until the changes have taken effect and the server re-started before indicating the change to peers, reducing difficultly for some clients to update their data.NimBLEService::getHandlewill now fetch the handle from the stack if not valid to avoid returning an invalid value.std::vectorinput to set/write values template.NimBLEHIDDevice::pnpwill now set the data correctly.- Check for Arduino component
- Fixed building with esp-idf version 5.x.
- Fixed pairing failing when the process was started by the peer first.
- Fixed building with esp-idf and Arduino component.
- Workaround for esp32s3 and esp32c3 not returning the correct txPower with some IDF versions.
Changed
NimBLEClient::secureConnectionnow takes an additional parameterbool async, if true, will send the secure command and return immediately with a true value for successfully sending the command, else false. This allows for asynchronously securing a connection.- Deleting the client instance from the
onDisconnectcallback is now supported. NimBLEClient::connectwill no longer cancel already in progress connections.NimBLEClient::setDataLennow returns bool, true if successful.NimBLEClient::updateConnParamsnow returns bool, true if successful.NimBLEClient::setPeerAddressnow returns a bool, true on success.NimBLEDevice::startSecuritynow takes and additional parameterint* rcPtrwhich will provide the return code from the stack if provided.NimBLEDevice::deleteClientno longer blocks tasks.NimBLEDevice::getAddresswill now return the address currently in use.NimBLEDevice::initnow returns a bool withtrueindicating success.NimBLEDevice::deinitnow returns a bool withtrueindicating success.NimBLEDevice::setDeviceNamenow returns a bool withtrueindicating success.NimBLEDevice::setCustomGapHandlernow returns a bool withtrueindicating success.NimBLEDevice::setOwnAddrTypenow returns a bool withtrueindicating success and works with non-esp32 devices.NimBLEDevice::setPowernow returns a bool value, true = success.NimBLEDevice::setMTUnow returns a bool value, true = success.NimBLEDevice::deleteAllBondsnow returns true on success, otherwise false.NimBLEEddystoneTLMinternal data struct typeBeaconDatais now public and usable by the application.NimBLEBeaconinternal data struct typeBeaconDatais now public and can be used by the application.- Removed tracking of client characteristic subscription status from
NimBLEServerandNimBLECharacteristicand instead uses
the functions and tracking in the host stack. NimBLECharacteristic::indicatenow takes the same parameters asnotify.NimBLECharacteristic::notifyandNimBLECharacteristic::indicatenow return abool, true = success.- Added optional
connHandleparameter toNimBLECharacteristic::notifyto allow for sending notifications to specific clients. NimBLEServerNow uses a std::array to store client connection handles instead of std::vector to reduce memory allocation.NimBLEExtAdvertisement: All functions that set data now returnbool, true = success.NimBLEAdvertisingAdvertising data is now stored in instances ofNimBLEAdvertisingDataand old vectors removed.NimBLEAdvertising::setAdvertisementDataandNimBLEAdvertising::setScanResponseDatanow returnbool, true = success.- Added optional
NimBLEAddressparameter toNimBLEAdvertising::startto allow for directed advertising to a peer. - All
NimBLEAdvertisingfunctions that change data values now returnbool, true = success. - All
NimBLEAdvertisementDatafunctions that change data values now returnbool, true = success. NimBLEAdvertisingadvertising complete callback is now defined as std::function to allow for using std::bind for callback functions.NimBLEAdvertisementData::setNamenow takes an optionalboolparameter to indicate if the name is complete or incomplete, default = complete.NimBLEAdvertisementDatamoved to it's own .h and .cpp files.NimBLEScan::starttakes a newbool restartparameter, defaulttrue, that will restart an already in progress scan and clear the duplicate filter so all devices will be discovered again.- Scan response data that is received without advertisement first will now create the device and send a callback.
NimBLEScan::startwill no longer clear cache or results if scanning is already in progress.NimBLEScan::startwill now allow the start command to be sent with updated parameters if already scanning.NimBLEScan::clearResultswill now reset the vector capacity to 0.- Host reset will now no longer restart scanning and instead will call
NimBLEScanCallbacks::onScanEnd. - Added optional
indexparameter toNimBLEAdvertisedDevice::getPayloadByType NimBLEAdvertisedDevice::getManufacturerDatanow takes an optional index parameter for use in the case of multiple manufacturer data fields.NimBLEUtils: Add missing GAP event strings.NimBLEUtils: Add missing return code strings.NimBLEUtils: Event/error code strings optimized.NimBLEAttValuecleanup and optimization.- cleaned up code, removed assert/abort calls, replaced with a configurable option to enable debug asserts.
Added
- (esp32 specific)
NimBLEDevice::setPowerLevelandNimBLEDevice::getPowerLevelwhich take and return the relatedesp_power_level*types. NimBLEDevice::setDefaultPhywhich will set the default preferred PHY for all connections.NimBLEDevice::getConnectedClients, which returns a vector of pointers to the currently connected client instances.NimBLEDevice::setOwnAddrfunction added, which takes auint8_t*orNimBLEAddress&and will set the mac address of the device, returnsbooltrue= success.NimBLEDevice::injectPassKeyUsed to send the pairing passkey instead of a return value from the client callback.NimBLEDevice::injectConfirmPasskeyUsed to send the numeric comparison pairing passkey confirmation instead of a return value from the client callback.NimBLEDevice::setDeviceNameto change the device name after initialization.NimBLECharacteristic::create2904which will specifically create a Characteristic Presentation Format (0x2904) descriptor.NimBLEAdvertising::refreshAdvertisingDatarefreshes the advertisement data while still actively advertising.NimBLEClient::updatePhyto request a PHY change with a peer.NimBLEClient::getPhyto read the current connection PHY setting.Configstruct toNimBLEClientto efficiently set single bit config settings.NimBLEClient::setSelfDeletethat takes the bool parametersdeleteOnDisconnectanddeleteOnConnectFail, which will configure the client to delete itself when disconnected or the connection attempt fails.NimBLEClient::setConfigandNimBLEClient::getConfigwhich takes or returns aNimBLEClient::Configobject respectively.NimBLEClient::cancelConnect()to cancel an in-progress connection, returnsbool, true = success.- Non-blocking
NimBLEClient::connectoption added via 2 newboolparameters added to the function: -
asyncConnect; if true, will send the connect command and return immediately.
-
exchangeMTU; if true will send the exchange MTU command upon connection.
NimBLEClientCallbacks::onConnectFailcallback that is called when the connection attempt fail while connecting asynchronously.NimBLEClientCallbacks::onMTUChangecallback which will be called when the MTU exchange completes and takes aNimBLEClient*anduint16_t MTUparameter.NimBLEClientCallbacks::onPhyUpdateand -NimBLEServerCallbacks::onPhyUpdateWhich are called when the PHY update is complete.- Extended scan example.
NimBLEServer::updatePhyto request a PHY change with a peer.NimBLEServer::getPhyto read the PHY of a peer connection.NimBLEServer::getClientwhich will create a client instance from the provided peer connHandle or connInfo to facilitate reading/write from the connected client.NimBLEServerCallbacks::onConnParamsUpdatecallback.NimBLEScan::eraseoverload that takes aconst NimBLEAdvertisedDevice*parameter.NimBLEScan::setScanPhyto enable/disable the PHY's to scan on (extended advertising only).NimBLEScan::setScanPeriodwhich will allow for setting a scan restart timer in the controller (extended advertising only).NimBLEAdvertisedDevice::isScannable()that returns true if the device is scannable.NimBLEAdvertisedDevice::beginandNimBLEAdvertisedDevice::endread-only iterators for convenience and use in range loops.NimBLEAdvertisedDevice::getAdvFlagsreturns the advertisement flags of the advertiser.NimBLEAdvertisedDevice::getPayloadByTypeGeneric use function that returns the data from the advertisement with the specified type.NimBLEAdvertisedDevice::haveTypeGeneric use function that returns true if the advertisement data contains a field with the specified type.- Support for esp32c6, esp32c2, esp32h2, and esp32p4.
NimBLEExtAdvertisement::removeData, which will remove the data of the specified type from the advertisement.NimBLEExtAdvertisement::addServiceUUID, which will append to the service uuids advertised.NimBLEExtAdvertisement::removeServiceUUID, which will remove the service from the uuids advertised.NimBLEExtAdvertisement::removeServices, which will remove all service uuids advertised.- New overloads for
NimBLEExtAdvertisement::setServiceDatawith the parametersconst NimBLEUUID& uuid, const uint8_t* data, size_t lengthandconst NimBLEUUID& uuid, const std::vector<uint8_t>& data. NimBLEExtAdvertisement::getDataLocation, which returns the location in the advertisement data of the type requested in parameteruint8_t type.NimBLEExtAdvertisement::toStringwhich returns a hex string representation of the advertisement data.NimBLEAdvertising::getAdvertisementData, which returns a reference to the currently set advertisement data.NimBLEAdvertising::getScanData, which returns a reference to the currently set scan response data.- New overloads for
NimBLEAdvertising::removeServiceUUIDandNimBLEAdvertisementData::removeServiceUUIDto accept aconst char* NimBLEAdvertising::clearData, which will clear the advertisement and scan response data.NimBLEAdvertising::setManufacturerDataOverload that takes aconst uint8_t*and , size_t` parameter.NimBLEAdvertising::setServiceDataOverload that takesconst NimBLEUUID& uuid,const uint8_t* data,size_t lengthas parameters.NimBLEAdvertising::setServiceDataOverload that takesconst NimBLEUUID& uuid,const std::vector<uint8_t>&as parameters.NimBLEAdvertising::setDiscoverableModeto allow applications to control the discoverability of the advertiser.NimBLEAdvertising::setAdvertisingCompleteCallbacksets the callback to call when advertising ends.NimBLEAdvertising::setPreferredParamsthat takes the min and max preferred connection parameters as an alternative forsetMinPreferredandsetMaxPreferred.NimBLEAdvertising::setAdvertisingIntervalSets the advertisement interval for min and max to the same value instead of callingsetMinIntervalandsetMaxIntervalseparately if there is not value difference.NimBLEAdvertisementData::removeData, which takes a parameteruint8_t type, the data type to remove.NimBLEAdvertisementData::toString, which will print the data in hex.NimBLEUtils::taskWaitwhich causes the calling task to wait for an event.NimBLEUtils::taskReleasereleases the task from and event.NimBLEUtils::generateAddrfunction added with will generate a random address and takes aboolparameter, true = create non-resolvable private address, otherwise a random static address is created, returnsNimBLEAddress.NimBLEUUID::getValuewhich returns a read-onlyuint8_tpointer to the UUID value.NimBLEUUID::reverseByteOrder, this will reverse the bytes of the UUID, which can be useful for advertising/logging.NimBLEUUIDconstructor overload that takes a reference toble_uuid_any_t.NimBLEAddress::isNrpamethod to test if an address is random non-resolvable.NimBLEAddress::isStaticmethod to test if an address is random static.NimBLEAddress::isPublicmethod to test if an address is a public address.NimBLEAddress::isNullmethods to test if an address is NULL.NimBLEAddress::getValuemethod which returns a read-only pointer to the address value.NimBLEAddress::reverseByteOrdermethod which will reverse the byte order of the address value.NimBLEHIDDevice::batteryLevelreturns the HID device battery level characteristic.NimBLEBeacon::setDataoverload that takesuint8_t* dataanduint8_t length.NimBLEHIDDevice::getPnpfunction added to access the pnp characteristic.NimBLEHIDDevice::getHidInfofunction added to access the hid info characteristic.