Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .github/workflows/arduino-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ jobs:
- "esp32:esp32:esp32"
- "esp32:esp32:esp32s3"
- "esp32:esp32:esp32c3"
nimble: [ false, true ]
nimble:
- false
- '1.4.0'
- '2.3.2'
fail-fast: false

steps:
Expand All @@ -40,9 +43,11 @@ jobs:
- uses: arduino/compile-sketches@v1
with:
fqbn: ${{ matrix.fqbn }}
sketch-paths: |
- examples/SerialToSerialBLE
libraries: |
- source-path: ./
- name: NimBLE-Arduino
${{ matrix.nimble != false && format('- name: NimBLE-Arduino@{0}', matrix.nimble) || '' }}
cli-compile-flags: |
- --build-property
- build.extra_flags="-DBLESERIAL_USE_NIMBLE=${{ matrix.nimble }}"
- build.extra_flags="-DBLESERIAL_USE_NIMBLE=${{ matrix.nimble != false }}"
31 changes: 28 additions & 3 deletions .github/workflows/platformio-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,31 @@ jobs:
os: [ ubuntu-latest ]
example:
- "SerialToSerialBLE"
# - "SerialToSerialBLE_TransparentUART"
- "SerialToSerialBLE_TransparentUART-NimBLE"
boards:
- [ esp32dev, esp32-s3-devkitc-1, esp32-c3-devkitm-1 ]
nimble: [ false, true ]
nimble:
- false
- '^1.4.0'
- '^2.0.0'

exclude:
- example: "SerialToSerialBLE_TransparentUART-NimBLE"
nimble: false
# - example: "SerialToSerialBLE_TransparentUART"
# nimble: '^1.4.0'
# - example: "SerialToSerialBLE_TransparentUART"
# nimble: '^2.0.0'
include:
- example: "SerialToSerialBLE_TransparentUART-NimBLE"
nimble: '^2.0.0'
os: ubuntu-latest
boards: [esp32dev, esp32-s3-devkitc-1, esp32-c3-devkitm-1]
- example: "SerialToSerialBLE_TransparentUART-NimBLE"
nimble: '^1.4.0'
os: ubuntu-latest
boards: [esp32dev, esp32-s3-devkitc-1, esp32-c3-devkitm-1]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -60,11 +82,14 @@ jobs:

- name: Build example
run: |
pio ci --lib="." --board=${{ join(matrix.boards, ' --board=') }} ${{ matrix.nimble && '--project-option="lib_deps=h2zero/NimBLE-Arduino@^1.4.0"' || '' }}
pio ci --lib="." --board=${{ join(matrix.boards, ' --board=') }} ${{ matrix.nimble && format('--project-option="lib_deps=h2zero/NimBLE-Arduino@{0}"', matrix.nimble) || '' }}
env:
PLATFORMIO_CI_SRC: "./examples/${{ matrix.example }}/*.ino"
PLATFORMIO_BUILD_UNFLAGS: |
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PLATFORMIO_BUILD_UNFLAGS environment variable appears to be incorrectly indented and may not be properly associated with the build step. It should be indented at the same level as PLATFORMIO_CI_SRC.

Copilot uses AI. Check for mistakes.
-std=gnu++11
PLATFORMIO_BUILD_FLAGS: |
-D BLESERIAL_USE_NIMBLE=${{ matrix.nimble }}
-std=gnu++17
-D BLESERIAL_USE_NIMBLE=${{ matrix.nimble != false }}
-Wall
-Wextra
-Wpedantic
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This library allows using Nordic UART Service (NUS) with ESP32 Arduino.
[![GitHub release](https://img.shields.io/github/v/release/senseshift/arduino-ble-serial)](https://github.com/senseshift/arduino-ble-serial/releases/latest)

[![PlatformIO CI](https://github.com/senseshift/arduino-ble-serial/actions/workflows/platformio-ci.yml/badge.svg)](https://github.com/senseshift/arduino-ble-serial/actions/workflows/platformio-ci.yml)
[![PlatformIO CI](https://github.com/senseshift/arduino-ble-serial/actions/workflows/arduino-ci.yml/badge.svg)](https://github.com/senseshift/arduino-ble-serial/actions/workflows/arduino-ci.yml)
[![Arduino CI](https://github.com/senseshift/arduino-ble-serial/actions/workflows/arduino-ci.yml/badge.svg)](https://github.com/senseshift/arduino-ble-serial/actions/workflows/arduino-ci.yml)

[![MIT](https://img.shields.io/github/license/senseshift/arduino-ble-serial)](/LICENSE)
[![GitHub contributors](https://img.shields.io/github/contributors/senseshift/arduino-ble-serial)](https://github.com/senseshift/arduino-ble-serial/graphs/contributors)
Expand Down
11 changes: 8 additions & 3 deletions examples/SerialToSerialBLE/SerialToSerialBLE.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@

String device_name = "ESP32-BLE-Slave";

// Mind the empty template argument (<>), it is required for
// the code to compile with the current Arduino C++ compiler version
BLESerial<> SerialBLE;
BLESerial SerialBLE;
// If you are using an older version of Arduino IDE or C++ compiler, you may need to use
// an empty template argument (<>), as Class Template Argument Deduction (CTAD) is not
// supported in C++ versions older than C++17. For more details, see:
// https://www.cppreference.com/w/cpp/language/ctad.html
//
// Uncomment the line below if you are using an older version of Arduino IDE/C++ compiler
// BLESerial<> SerialBLE;

// FOR ETL: Uncomment one of the following lines
// BLESerial<etl::queue<uint8_t, 255, etl::memory_model::MEMORY_MODEL_SMALL>> SerialBLE;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <BLESerial.h>

// FOR ETL: Uncomment the following lines
// #include <Embedded_Template_Library.h>
// #include <etl/queue.h>
// #include <etl/circular_buffer.h>

BLESerial SerialBLE;
// If you are using an older version of Arduino IDE or C++ compiler, you may need to use
// an empty template argument (<>), as Class Template Argument Deduction (CTAD) is not
// supported in C++ versions older than C++17. For more details, see:
// https://www.cppreference.com/w/cpp/language/ctad.html
//
// Uncomment the line below if you are using an older version of Arduino IDE/C++ compiler
// BLESerial<> SerialBLE;

// FOR ETL: Uncomment one of the following lines
// BLESerial<etl::queue<uint8_t, 255, etl::memory_model::MEMORY_MODEL_SMALL>> SerialBLE;
// OR
// BLESerial<etl::circular_buffer<uint8_t, 255>> SerialBLE;

void setup() {
BLEDevice::init("ESP32-BLE-Slave");

BLEServer* pServer = BLEDevice::createServer();

// Transparent UART Service
// https://developerhelp.microchip.com/xwiki/bin/view/applications/ble/android-development-for-bm70rn4870/transparent-uart-service-for-bm70rn4870/
auto pService = pServer->createService("49535343-FE7D-4AE5-8FA9-9FAFD205E455");

auto pRxCharacteristic = pService->createCharacteristic("49535343-1E4D-4BD9-BA61-23C647249616", NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::WRITE_NR | NIMBLE_PROPERTY::NOTIFY);
auto pTxCharacteristic = pService->createCharacteristic("49535343-8841-43F4-A8D4-ECBE34729BB3", NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY);

SerialBLE.begin(pRxCharacteristic, pTxCharacteristic);

BLEAdvertising* pAdvertising = pServer->getAdvertising();
pAdvertising->start();
}

void loop() {
if (Serial.available()) {
SerialBLE.write(Serial.read());
SerialBLE.flush();
}
if (SerialBLE.available()) {
Serial.write(SerialBLE.read());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <BLESerial.h>

// FOR ETL: Uncomment the following lines
// #include <Embedded_Template_Library.h>
// #include <etl/queue.h>
// #include <etl/circular_buffer.h>

BLESerial SerialBLE;
// If you are using an older version of Arduino IDE or C++ compiler, you may need to use
// an empty template argument (<>), as Class Template Argument Deduction (CTAD) is not
// supported in C++ versions older than C++17. For more details, see:
// https://www.cppreference.com/w/cpp/language/ctad.html
//
// Uncomment the line below if you are using an older version of Arduino IDE/C++ compiler
// BLESerial<> SerialBLE;

// FOR ETL: Uncomment one of the following lines
// BLESerial<etl::queue<uint8_t, 255, etl::memory_model::MEMORY_MODEL_SMALL>> SerialBLE;
// OR
// BLESerial<etl::circular_buffer<uint8_t, 255>> SerialBLE;

void setup() {
BLEDevice::init("ESP32-BLE-Slave");

BLEServer* pServer = BLEDevice::createServer();

// Transparent UART Service
// https://developerhelp.microchip.com/xwiki/bin/view/applications/ble/android-development-for-bm70rn4870/transparent-uart-service-for-bm70rn4870/
auto pService = pServer->createService("49535343-FE7D-4AE5-8FA9-9FAFD205E455");

auto pRxCharacteristic = pService->createCharacteristic("49535343-1E4D-4BD9-BA61-23C647249616", BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_WRITE_NR | BLECharacteristic::PROPERTY_NOTIFY);
auto pTxCharacteristic = pService->createCharacteristic("49535343-8841-43F4-A8D4-ECBE34729BB3", BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY);

SerialBLE.begin(pRxCharacteristic, pTxCharacteristic);

BLEAdvertising* pAdvertising = pServer->getAdvertising();
pAdvertising->start();
}

void loop() {
if (Serial.available()) {
SerialBLE.write(Serial.read());
SerialBLE.flush();
}
if (SerialBLE.available()) {
Serial.write(SerialBLE.read());
}
}
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json",
"name": "Serial_BLE",
"version": "1.1.3",
"version": "1.2.0",
"description": "Customizable Arduino and ESP32 BLE Serial library, compliant with Nordic UART Service and others.",
"keywords": [
"serial",
Expand Down Expand Up @@ -46,6 +46,6 @@
"srcDir": "src"
},
"dependencies": {
"ESP32 BLE Arduino": "^2.0.0"
"BLE": "^2.0.0"
Copy link

Copilot AI Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dependency name change from "ESP32 BLE Arduino" to "BLE" may break existing installations and could be ambiguous. Consider keeping the specific library name or providing migration documentation.

Suggested change
"BLE": "^2.0.0"
"ESP32 BLE Arduino": "^2.0.0"

Copilot uses AI. Check for mistakes.
}
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Serial_BLE
version=1.1.3
version=1.2.0
author=Leonid Meleshin <[email protected]>
maintainer=Leonid Meleshin <[email protected]>
sentence=Customizable BLE Serial (UART) library.
Expand Down
30 changes: 30 additions & 0 deletions src/BLESerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
# include <BLEDevice.h>
#endif // BLESERIAL_USE_NIMBLE

#if !defined(BLESERIAL_NIMBLE_VERSION_MAJOR) && defined(BLESERIAL_USE_NIMBLE) && BLESERIAL_USE_NIMBLE
# if __has_include(<NimBLEAdvertisementData.h>)
# define BLESERIAL_NIMBLE_VERSION_MAJOR 2
// # warning "Using NimBLE version 2"
# else // __has_include(<NimBLEAdvertisementData.h>)
# define BLESERIAL_NIMBLE_VERSION_MAJOR 1
// # warning "Using NimBLE version 1"
# endif // __has_include(<NimBLEAdvertisementData.h>)
#endif // BLESERIAL_USE_NIMBLE

#ifndef BLESERIAL_USE_STL
# define BLESERIAL_USE_STL true
#endif // BLESERIAL_USE_STL
Expand Down Expand Up @@ -262,7 +272,17 @@ class BLESerialServerCallbacks : public BLEServerCallbacks {
public:
explicit BLESerialServerCallbacks(BLESerial<T>* bleSerial) : bleSerial(bleSerial) {}

#if defined(BLESERIAL_USE_NIMBLE) && BLESERIAL_USE_NIMBLE
# if defined(BLESERIAL_NIMBLE_VERSION_MAJOR) && BLESERIAL_NIMBLE_VERSION_MAJOR >= 2
// # warning "Using NimBLE version 2 for BLESerialServerCallbacks"
void onDisconnect(NimBLEServer* pServer, NimBLEConnInfo& connInfo, int reason) override
# else // BLESERIAL_NIMBLE_VERSION_MAJOR >= 2
// # warning "Using NimBLE version 1 for BLESerialServerCallbacks"
void onDisconnect(NimBLEServer* pServer, ble_gap_conn_desc* desc) override
# endif // BLESERIAL_NIMBLE_VERSION_MAJOR >= 2
#else // BLESERIAL_USE_NIMBLE
void onDisconnect(BLEServer* pServer) override
#endif // BLESERIAL_USE_NIMBLE
{
auto* pAdvertising = pServer->getAdvertising();
if (pAdvertising == nullptr) {
Expand All @@ -280,7 +300,17 @@ class BLESerialCharacteristicCallbacks : public BLECharacteristicCallbacks {
public:
explicit BLESerialCharacteristicCallbacks(BLESerial<T>* bleSerial) : bleSerial(bleSerial) {}

#if defined(BLESERIAL_USE_NIMBLE) && BLESERIAL_USE_NIMBLE
# if defined(BLESERIAL_NIMBLE_VERSION_MAJOR) && BLESERIAL_NIMBLE_VERSION_MAJOR >= 2
// # warning "Using NimBLE version 2 for BLESerialCharacteristicCallbacks"
void onWrite(NimBLECharacteristic* pCharacteristic, NimBLEConnInfo& connInfo) override
# else // BLESERIAL_NIMBLE_VERSION_MAJOR >= 2
// # warning "Using NimBLE version 1 for BLESerialCharacteristicCallbacks"
void onWrite(NimBLECharacteristic* pCharacteristic, ble_gap_conn_desc* desc) override
# endif // BLESERIAL_NIMBLE_VERSION_MAJOR >= 2
#else // BLESERIAL_USE_NIMBLE
void onWrite(BLECharacteristic* pCharacteristic) override
#endif // BLESERIAL_USE_NIMBLE
{
if (pCharacteristic != bleSerial->m_pRxCharacteristic) {
return;
Expand Down