Release 2.0.0

This commit is contained in:
h2zero 2024-12-14 14:37:09 -07:00 committed by Ryan Powell
parent 675d6bbf0d
commit a6ed1933bc
8 changed files with 60 additions and 56 deletions

17
.github/workflows/sponsors.yml vendored Normal file
View file

@ -0,0 +1,17 @@
name: Generate Sponsors README
on:
workflow_dispatch:
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
- name: Generate Sponsors 💖
uses: JamesIves/github-sponsors-readme-action@v1.5.4
with:
token: ${{ secrets.PAT }}
file: 'README.md'

View file

@ -1,7 +1,7 @@
# Changelog # Changelog
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## [Unreleased]
## [2.0.0] 2024-12-14
## **Breaking changes** ## **Breaking changes**
- All connection oriented callbacks now receive a reference to `NimBLEConnInfo`, the `ble_gap_conn_desc` has also been replace with `NimBLEConnInfo` in the functions that received it. - All connection oriented callbacks now receive a reference to `NimBLEConnInfo`, the `ble_gap_conn_desc` has also been replace with `NimBLEConnInfo` in the functions that received it.

View file

@ -1,19 +1,20 @@
[Latest release ![Release Version](https://img.shields.io/github/release/h2zero/esp-nimble-cpp.svg?style=plastic) [![Release Version](https://img.shields.io/github/release/h2zero/esp-nimble-cpp.svg?style=plastic)
![Release Date](https://img.shields.io/github/release-date/h2zero/esp-nimble-cpp.svg?style=plastic)](https://github.com/h2zero/esp-nimble-cpp/releases/latest/) ![Release Date](https://img.shields.io/github/release-date/h2zero/esp-nimble-cpp.svg?style=plastic)](https://github.com/h2zero/esp-nimble-cpp/releases/latest/)
Need help? Have questions or suggestions? Join the [![Gitter](https://badges.gitter.im/NimBLE-Arduino/community.svg)](https://gitter.im/NimBLE-Arduino/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) > [!IMPORTANT]
<br/> > Version 2 is now released!
> Check out the [1.x to 2.x Migration Guide](docs/1.x_to2.x_migration_guide.md) and [Release Notes](https://github.com/h2zero/esp-nimble-cpp/releases/latest/)
# esp-nimble-cpp # esp-nimble-cpp
NimBLE CPP library for use with ESP32 that attempts to maintain compatibility with the [nkolban cpp_uitls BLE API](https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils). NimBLE CPP library for use with ESP32 that attempts to maintain compatibility with the [nkolban cpp_utils BLE API](https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils).
**An Arduino version of this library, including NimBLE, can be [found here.](https://github.com/h2zero/NimBLE-Arduino)** **An Arduino version of this library, including NimBLE, can be [found here.](https://github.com/h2zero/NimBLE-Arduino)**
This library **significantly** reduces resource usage and improves performance for ESP32 BLE applications as compared This library **significantly** reduces resource usage and improves performance for ESP32 BLE applications as compared
with the bluedroid based library. The goal is to maintain, as much as reasonable, compatibility with the original with the bluedroid based library. The goal is to maintain, as much as reasonable, compatibility with the original
library but refactored to use the NimBLE stack. In addition, this library will be more actively developed and maintained library but using the NimBLE stack. In addition, this library will be more actively developed and maintained
to provide improved capabilites and stability over the original. to provide improved capabilities and stability over the original.
**Testing shows a nearly 50% reduction in flash use and approx. 100kB less ram consumed vs the original!** **Testing shows a nearly 50% reduction in flash use and approx. 100kB less ram consumed vs the original!**
*Your results may vary* *Your results may vary*
@ -35,16 +36,6 @@ Configure settings in `NimBLE Options`.
Call `NimBLEDevice::init("");` in `app_main`. Call `NimBLEDevice::init("");` in `app_main`.
<br/> <br/>
### ESP-IDF v3.2 & v3.3
The NimBLE component does not come with these versions of IDF (now included in 3.3.2 and above).
A backport that works in these versions has been created and is [available here](https://github.com/h2zero/esp-nimble-component).
Download or clone that repo into your project/components folder and run menuconfig.
Configure settings in `main menu -> NimBLE Options`.
`#include "NimBLEDevice.h"` in main.cpp.
Call `NimBLEDevice::init("");` in `app_main`.
<br/>
# Using # Using
This library is intended to be compatible with the original ESP32 BLE functions and types with minor changes. This library is intended to be compatible with the original ESP32 BLE functions and types with minor changes.
@ -62,6 +53,14 @@ When using this library along with Arduino and compiling with *CMake* you must a
in your project/CMakeLists.txt after the line `include($ENV{IDF_PATH}/tools/cmake/project.cmake)` to prevent Arduino from releasing BLE memory. in your project/CMakeLists.txt after the line `include($ENV{IDF_PATH}/tools/cmake/project.cmake)` to prevent Arduino from releasing BLE memory.
<br> <br>
# Sponsors
Thank you to all the sponsors who support this project!
<!-- sponsors --><!-- sponsors -->
If you use this library for a commercial product please consider [sponsoring the development](https://github.com/sponsors/h2zero) to ensure the continued updates and maintenance.
<br/>
# Acknowledgments # Acknowledgments
* [nkolban](https://github.com/nkolban) and [chegewara](https://github.com/chegewara) for the [original esp32 BLE library](https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils) this project was derived from. * [nkolban](https://github.com/nkolban) and [chegewara](https://github.com/chegewara) for the [original esp32 BLE library](https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils) this project was derived from.
* [beegee-tokyo](https://github.com/beegee-tokyo) for contributing your time to test/debug and contributing the beacon examples. * [beegee-tokyo](https://github.com/beegee-tokyo) for contributing your time to test/debug and contributing the beacon examples.

View file

@ -1,5 +1,4 @@
# Overview # Overview
This is a C++ BLE library for the ESP32 that uses the NimBLE host stack instead of bluedroid. This is a C++ BLE library for the ESP32 that uses the NimBLE host stack instead of bluedroid.
The aim is to maintain, as much as reasonable, the original bluedroid C++ & Arduino BLE API by while adding new features The aim is to maintain, as much as reasonable, the original bluedroid C++ & Arduino BLE API by while adding new features
and making improvements in performance, resource use, and stability. and making improvements in performance, resource use, and stability.
@ -23,16 +22,6 @@ Configure settings in `NimBLE Options`.
Call `NimBLEDevice::init` in `app_main`. Call `NimBLEDevice::init` in `app_main`.
<br/> <br/>
### v3.2 & v3.3
The NimBLE component does not come with these versions of IDF (now included in 3.3.2 and above).
A backport that works in these versions has been created and is [available here](https://github.com/h2zero/esp-nimble-component).
Download or clone that repo into your project/components folder and run menuconfig.
Configure settings in `main menu -> NimBLE Options`.
`#include "NimBLEDevice.h"` in main.cpp.
Call `NimBLEDevice::init` in `app_main`.
<br/>
# Using # Using
This library is intended to be compatible with the original ESP32 BLE functions and types with minor changes. This library is intended to be compatible with the original ESP32 BLE functions and types with minor changes.
@ -43,12 +32,13 @@ If you are familiar with the original library, see: [The migration guide](Migrat
For more advanced usage see [Usage tips](Usage_tips.md) for more performance and optimization. For more advanced usage see [Usage tips](Usage_tips.md) for more performance and optimization.
<br/> <br/>
# Need help? Have a question or suggestion? # Sponsors
Come chat on [gitter](https://gitter.im/NimBLE-Arduino/community?utm_source=share-link&utm_medium=link&utm_campaign=share-link) or open an issue at [NimBLE-Arduino](https://github.com/h2zero/NimBLE-Arduino/issues) or [esp-nimble-cpp](https://github.com/h2zero/esp-nimble-cpp/issues) Thank you to all the sponsors who support this project!
If you use this library for a commercial product please consider [sponsoring the development](https://github.com/sponsors/h2zero) to ensure the continued updates and maintenance.
<br/> <br/>
# Acknowledgments # Acknowledgments
* [nkolban](https://github.com/nkolban) and [chegewara](https://github.com/chegewara) for the [original esp32 BLE library](https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils) this project was derived from. * [nkolban](https://github.com/nkolban) and [chegewara](https://github.com/chegewara) for the [original esp32 BLE library](https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils) this project was derived from.
* [beegee-tokyo](https://github.com/beegee-tokyo) for contributing your time to test/debug and contributing the beacon examples. * [beegee-tokyo](https://github.com/beegee-tokyo) for contributing your time to test/debug and contributing the beacon examples.
* [Jeroen88](https://github.com/Jeroen88) for the amazing help debugging and improving the client code. * [Jeroen88](https://github.com/Jeroen88) for the amazing help debugging and improving the client code.

View file

@ -14,8 +14,8 @@
#define CHARACTERISTIC_UUID "1234" #define CHARACTERISTIC_UUID "1234"
static const NimBLEAdvertisedDevice* advDevice; static const NimBLEAdvertisedDevice* advDevice;
static bool doConnect = false; static bool doConnect = false;
static uint32_t scanTime = 10 * 1000; // In milliseconds, 0 = scan forever static uint32_t scanTimeMs = 10 * 1000; // In milliseconds, 0 = scan forever
/** Define the PHY's to use when connecting to peer devices, can be 1, 2, or all 3 (default).*/ /** Define the PHY's to use when connecting to peer devices, can be 1, 2, or all 3 (default).*/
static uint8_t connectPhys = BLE_GAP_LE_PHY_CODED_MASK | BLE_GAP_LE_PHY_1M_MASK /*| BLE_GAP_LE_PHY_2M_MASK */; static uint8_t connectPhys = BLE_GAP_LE_PHY_CODED_MASK | BLE_GAP_LE_PHY_1M_MASK /*| BLE_GAP_LE_PHY_2M_MASK */;
@ -26,7 +26,7 @@ class ClientCallbacks : public NimBLEClientCallbacks {
void onDisconnect(NimBLEClient* pClient, int reason) override { void onDisconnect(NimBLEClient* pClient, int reason) override {
printf("%s Disconnected, reason = %d - Starting scan\n", pClient->getPeerAddress().toString().c_str(), reason); printf("%s Disconnected, reason = %d - Starting scan\n", pClient->getPeerAddress().toString().c_str(), reason);
NimBLEDevice::getScan()->start(scanTime); NimBLEDevice::getScan()->start(scanTimeMs);
} }
} clientCallbacks; } clientCallbacks;
@ -123,7 +123,7 @@ extern "C" void app_main(void) {
* Start scanning for advertisers for the scan time specified (in milliseconds) 0 = forever * Start scanning for advertisers for the scan time specified (in milliseconds) 0 = forever
* Optional callback for when scanning stops. * Optional callback for when scanning stops.
*/ */
pScan->start(scanTime); pScan->start(scanTimeMs);
printf("Scanning for peripherals\n"); printf("Scanning for peripherals\n");
@ -137,7 +137,7 @@ extern "C" void app_main(void) {
} }
doConnect = false; doConnect = false;
NimBLEDevice::getScan()->start(scanTime); NimBLEDevice::getScan()->start(scanTimeMs);
} }
vTaskDelay(pdMS_TO_TICKS(10)); vTaskDelay(pdMS_TO_TICKS(10));
} }

View file

@ -9,8 +9,8 @@
#include <NimBLEDevice.h> #include <NimBLEDevice.h>
static uint32_t scanTime = 10 * 1000; // In milliseconds, 0 = scan forever static uint32_t scanTimeMs = 10 * 1000; // In milliseconds, 0 = scan forever
static NimBLEScan::Phy scanPhy = NimBLEScan::Phy::SCAN_ALL; static NimBLEScan::Phy scanPhy = NimBLEScan::Phy::SCAN_ALL;
/** Define a class to handle the callbacks when advertisements are received */ /** Define a class to handle the callbacks when advertisements are received */
class ScanCallbacks : public NimBLEScanCallbacks { class ScanCallbacks : public NimBLEScanCallbacks {
@ -43,7 +43,7 @@ class ScanCallbacks : public NimBLEScanCallbacks {
NimBLEScan* pScan = NimBLEDevice::getScan(); NimBLEScan* pScan = NimBLEDevice::getScan();
pScan->setPhy(scanPhy); pScan->setPhy(scanPhy);
pScan->start(scanTime); pScan->start(scanTimeMs);
} }
} scanCallbacks; } scanCallbacks;
@ -63,7 +63,7 @@ extern "C" void app_main(void) {
/** Set the initial PHY's to scan on, default is SCAN_ALL */ /** Set the initial PHY's to scan on, default is SCAN_ALL */
pScan->setPhy(scanPhy); pScan->setPhy(scanPhy);
/** Start scanning for scanTime */ /** Start scanning for scanTimeMs */
pScan->start(scanTime); pScan->start(scanTimeMs);
printf("Scanning for peripherals\n"); printf("Scanning for peripherals\n");
} }

View file

@ -10,8 +10,8 @@
#include <NimBLEDevice.h> #include <NimBLEDevice.h>
static const NimBLEAdvertisedDevice* advDevice; static const NimBLEAdvertisedDevice* advDevice;
static bool doConnect = false; static bool doConnect = false;
static uint32_t scanTime = 5000; /** scan time in milliseconds, 0 = scan forever */ static uint32_t scanTimeMs = 5000; /** scan time in milliseconds, 0 = scan forever */
/** None of these are required as they will be handled by the library with defaults. ** /** None of these are required as they will be handled by the library with defaults. **
** Remove as you see fit for your needs */ ** Remove as you see fit for your needs */
@ -20,7 +20,7 @@ class ClientCallbacks : public NimBLEClientCallbacks {
void onDisconnect(NimBLEClient* pClient, int reason) override { void onDisconnect(NimBLEClient* pClient, int reason) override {
printf("%s Disconnected, reason = %d - Starting scan\n", pClient->getPeerAddress().toString().c_str(), reason); printf("%s Disconnected, reason = %d - Starting scan\n", pClient->getPeerAddress().toString().c_str(), reason);
NimBLEDevice::getScan()->start(scanTime, false, true); NimBLEDevice::getScan()->start(scanTimeMs, false, true);
} }
/********************* Security handled here *********************/ /********************* Security handled here *********************/
@ -48,10 +48,10 @@ class ClientCallbacks : public NimBLEClientCallbacks {
return; return;
} }
} }
} clientCB; } clientCallbacks;
/** Define a class to handle the callbacks when scan events are received */ /** Define a class to handle the callbacks when scan events are received */
class scanCallbacks : public NimBLEScanCallbacks { class ScanCallbacks : public NimBLEScanCallbacks {
void onResult(const NimBLEAdvertisedDevice* advertisedDevice) override { void onResult(const NimBLEAdvertisedDevice* advertisedDevice) override {
printf("Advertised Device found: %s\n", advertisedDevice->toString().c_str()); printf("Advertised Device found: %s\n", advertisedDevice->toString().c_str());
if (advertisedDevice->isAdvertisingService(NimBLEUUID("DEAD"))) { if (advertisedDevice->isAdvertisingService(NimBLEUUID("DEAD"))) {
@ -68,9 +68,9 @@ class scanCallbacks : public NimBLEScanCallbacks {
/** Callback to process the results of the completed scan or restart it */ /** Callback to process the results of the completed scan or restart it */
void onScanEnd(const NimBLEScanResults& results, int reason) override { void onScanEnd(const NimBLEScanResults& results, int reason) override {
printf("Scan Ended, reason: %d, device count: %d; Restarting scan\n", reason, results.getCount()); printf("Scan Ended, reason: %d, device count: %d; Restarting scan\n", reason, results.getCount());
NimBLEDevice::getScan()->start(scanTime, false, true); NimBLEDevice::getScan()->start(scanTimeMs, false, true);
} }
} scanCB; } scanCallbacks;
/** Notification / Indication receiving handler callback */ /** Notification / Indication receiving handler callback */
void notifyCB(NimBLERemoteCharacteristic* pRemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify) { void notifyCB(NimBLERemoteCharacteristic* pRemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify) {
@ -121,7 +121,7 @@ bool connectToServer() {
printf("New client created\n"); printf("New client created\n");
pClient->setClientCallbacks(&clientCB, false); pClient->setClientCallbacks(&clientCallbacks, false);
/** /**
* Set initial connection parameters: * Set initial connection parameters:
* These settings are safe for 3 clients to connect reliably, can go faster if you have less * These settings are safe for 3 clients to connect reliably, can go faster if you have less
@ -241,8 +241,7 @@ bool connectToServer() {
return true; return true;
} }
extern "C" extern "C" void app_main(void) {
void app_main(void) {
printf("Starting NimBLE Client\n"); printf("Starting NimBLE Client\n");
/** Initialize NimBLE and set the device name */ /** Initialize NimBLE and set the device name */
NimBLEDevice::init("NimBLE-Client"); NimBLEDevice::init("NimBLE-Client");
@ -270,7 +269,7 @@ void app_main(void) {
NimBLEScan* pScan = NimBLEDevice::getScan(); NimBLEScan* pScan = NimBLEDevice::getScan();
/** Set the callbacks to call when scan events occur, no duplicates */ /** Set the callbacks to call when scan events occur, no duplicates */
pScan->setScanCallbacks(&scanCB, false); pScan->setScanCallbacks(&scanCallbacks, false);
/** Set scan interval (how often) and window (how long) in milliseconds */ /** Set scan interval (how often) and window (how long) in milliseconds */
pScan->setInterval(100); pScan->setInterval(100);
@ -283,7 +282,7 @@ void app_main(void) {
pScan->setActiveScan(true); pScan->setActiveScan(true);
/** Start scanning for advertisers */ /** Start scanning for advertisers */
pScan->start(scanTime); pScan->start(scanTimeMs);
printf("Scanning for peripherals\n"); printf("Scanning for peripherals\n");
/** Loop here until we find a device we want to connect to */ /** Loop here until we find a device we want to connect to */
@ -299,7 +298,7 @@ void app_main(void) {
printf("Failed to connect, starting scan\n"); printf("Failed to connect, starting scan\n");
} }
NimBLEDevice::getScan()->start(scanTime, false, true); NimBLEDevice::getScan()->start(scanTimeMs, false, true);
} }
} }
} }

View file

@ -5,7 +5,6 @@
"keywords": [ "keywords": [
"BLE", "BLE",
"espidf", "espidf",
"arduino",
"espressif", "espressif",
"esp32", "esp32",
"nimble" "nimble"