Skip to content

Commit

Permalink
Release v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
h2zero committed Dec 14, 2024
1 parent 675d6bb commit ae282a0
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 56 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/sponsors.yml
Original file line number Diff line number Diff line change
@@ -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'
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

All notable changes to this project will be documented in this file.
## [Unreleased]

## [2.0.0] 2024-12-14

## **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.
Expand Down
31 changes: 15 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/)

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)
<br/>
> [!IMPORTANT]
> 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

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)**

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
library but refactored to use the NimBLE stack. In addition, this library will be more actively developed and maintained
to provide improved capabilites and stability over the original.
library but using the NimBLE stack. In addition, this library will be more actively developed and maintained
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!**
*Your results may vary*
Expand All @@ -35,16 +36,6 @@ Configure settings in `NimBLE Options`.
Call `NimBLEDevice::init("");` in `app_main`.
<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
This library is intended to be compatible with the original ESP32 BLE functions and types with minor changes.

Expand All @@ -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.
<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
* [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.
Expand Down
18 changes: 4 additions & 14 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Overview

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
and making improvements in performance, resource use, and stability.
Expand All @@ -23,16 +22,6 @@ Configure settings in `NimBLE Options`.
Call `NimBLEDevice::init` in `app_main`.
<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
This library is intended to be compatible with the original ESP32 BLE functions and types with minor changes.

Expand All @@ -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.
<br/>

# Need help? Have a question or suggestion?
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)
# Sponsors
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/>

# 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.
* [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.
Expand Down
10 changes: 5 additions & 5 deletions examples/Bluetooth_5/NimBLE_extended_client/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#define CHARACTERISTIC_UUID "1234"

static const NimBLEAdvertisedDevice* advDevice;
static bool doConnect = false;
static uint32_t scanTime = 10 * 1000; // In milliseconds, 0 = scan forever
static bool doConnect = false;
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).*/
static uint8_t connectPhys = BLE_GAP_LE_PHY_CODED_MASK | BLE_GAP_LE_PHY_1M_MASK /*| BLE_GAP_LE_PHY_2M_MASK */;
Expand All @@ -26,7 +26,7 @@ class ClientCallbacks : public NimBLEClientCallbacks {

void onDisconnect(NimBLEClient* pClient, int reason) override {
printf("%s Disconnected, reason = %d - Starting scan\n", pClient->getPeerAddress().toString().c_str(), reason);
NimBLEDevice::getScan()->start(scanTime);
NimBLEDevice::getScan()->start(scanTimeMs);
}
} clientCallbacks;

Expand Down Expand Up @@ -123,7 +123,7 @@ extern "C" void app_main(void) {
* Start scanning for advertisers for the scan time specified (in milliseconds) 0 = forever
* Optional callback for when scanning stops.
*/
pScan->start(scanTime);
pScan->start(scanTimeMs);

printf("Scanning for peripherals\n");

Expand All @@ -137,7 +137,7 @@ extern "C" void app_main(void) {
}

doConnect = false;
NimBLEDevice::getScan()->start(scanTime);
NimBLEDevice::getScan()->start(scanTimeMs);
}
vTaskDelay(pdMS_TO_TICKS(10));
}
Expand Down
10 changes: 5 additions & 5 deletions examples/Bluetooth_5/NimBLE_extended_scan/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#include <NimBLEDevice.h>

static uint32_t scanTime = 10 * 1000; // In milliseconds, 0 = scan forever
static NimBLEScan::Phy scanPhy = NimBLEScan::Phy::SCAN_ALL;
static uint32_t scanTimeMs = 10 * 1000; // In milliseconds, 0 = scan forever
static NimBLEScan::Phy scanPhy = NimBLEScan::Phy::SCAN_ALL;

/** Define a class to handle the callbacks when advertisements are received */
class ScanCallbacks : public NimBLEScanCallbacks {
Expand Down Expand Up @@ -43,7 +43,7 @@ class ScanCallbacks : public NimBLEScanCallbacks {

NimBLEScan* pScan = NimBLEDevice::getScan();
pScan->setPhy(scanPhy);
pScan->start(scanTime);
pScan->start(scanTimeMs);
}
} scanCallbacks;

Expand All @@ -63,7 +63,7 @@ extern "C" void app_main(void) {
/** Set the initial PHY's to scan on, default is SCAN_ALL */
pScan->setPhy(scanPhy);

/** Start scanning for scanTime */
pScan->start(scanTime);
/** Start scanning for scanTimeMs */
pScan->start(scanTimeMs);
printf("Scanning for peripherals\n");
}
25 changes: 12 additions & 13 deletions examples/NimBLE_Client/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <NimBLEDevice.h>

static const NimBLEAdvertisedDevice* advDevice;
static bool doConnect = false;
static uint32_t scanTime = 5000; /** scan time in milliseconds, 0 = scan forever */
static bool doConnect = false;
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. **
** Remove as you see fit for your needs */
Expand All @@ -20,7 +20,7 @@ class ClientCallbacks : public NimBLEClientCallbacks {

void onDisconnect(NimBLEClient* pClient, int reason) override {
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 *********************/
Expand Down Expand Up @@ -48,10 +48,10 @@ class ClientCallbacks : public NimBLEClientCallbacks {
return;
}
}
} clientCB;
} clientCallbacks;

/** 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 {
printf("Advertised Device found: %s\n", advertisedDevice->toString().c_str());
if (advertisedDevice->isAdvertisingService(NimBLEUUID("DEAD"))) {
Expand All @@ -68,9 +68,9 @@ class scanCallbacks : public NimBLEScanCallbacks {
/** Callback to process the results of the completed scan or restart it */
void onScanEnd(const NimBLEScanResults& results, int reason) override {
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 */
void notifyCB(NimBLERemoteCharacteristic* pRemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify) {
Expand Down Expand Up @@ -121,7 +121,7 @@ bool connectToServer() {

printf("New client created\n");

pClient->setClientCallbacks(&clientCB, false);
pClient->setClientCallbacks(&clientCallbacks, false);
/**
* Set initial connection parameters:
* These settings are safe for 3 clients to connect reliably, can go faster if you have less
Expand Down Expand Up @@ -241,8 +241,7 @@ bool connectToServer() {
return true;
}

extern "C"
void app_main(void) {
extern "C" void app_main(void) {
printf("Starting NimBLE Client\n");
/** Initialize NimBLE and set the device name */
NimBLEDevice::init("NimBLE-Client");
Expand Down Expand Up @@ -270,7 +269,7 @@ void app_main(void) {
NimBLEScan* pScan = NimBLEDevice::getScan();

/** 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 */
pScan->setInterval(100);
Expand All @@ -283,7 +282,7 @@ void app_main(void) {
pScan->setActiveScan(true);

/** Start scanning for advertisers */
pScan->start(scanTime);
pScan->start(scanTimeMs);
printf("Scanning for peripherals\n");

/** Loop here until we find a device we want to connect to */
Expand All @@ -299,7 +298,7 @@ void app_main(void) {
printf("Failed to connect, starting scan\n");
}

NimBLEDevice::getScan()->start(scanTime, false, true);
NimBLEDevice::getScan()->start(scanTimeMs, false, true);
}
}
}
1 change: 0 additions & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"keywords": [
"BLE",
"espidf",
"arduino",
"espressif",
"esp32",
"nimble"
Expand Down

0 comments on commit ae282a0

Please sign in to comment.