Skip to content

Conversation

@lucasssvaz
Copy link
Member

Description of Change

This pull request introduces a new example for connecting to multiple BLE servers simultaneously and refactors how BLE characteristic descriptors are managed in the NimBLE client implementation. The main improvements include lazy-loading of descriptors to avoid deadlocks, on-demand retrieval for notifications, and a new example demonstrating multi-server client logic.

New Example: Multi-Server BLE Client

  • Added Client_multiconnect.ino example, which demonstrates how to scan for, connect to, and interact with up to three BLE servers at once, including handling notifications and reconnections.
  • Added a corresponding ci.yml configuration for the new example, specifying build requirements for BLE support.

Descriptor Management Refactor (NimBLE Client):

  • Changed BLERemoteCharacteristic to lazily retrieve descriptors only when needed (e.g., for notifications or explicit requests), instead of during construction. This avoids potential deadlocks with NimBLE and improves reliability. [1] [2]
  • Updated getDescriptors(), getDescriptor(), and setNotify() to automatically retrieve descriptors on-demand if they have not been loaded yet. This ensures correct behavior for notification registration and descriptor access. [1] [2] [3]
  • Fixed the descriptor discovery range in retrieveDescriptors() to use the remote service's end handle, ensuring all relevant descriptors are found.

Test Scenarios

Tested Locally

Related links

Closes #11796
Closes #11811

@lucasssvaz lucasssvaz self-assigned this Nov 3, 2025
@lucasssvaz lucasssvaz requested a review from SuGlider as a code owner November 3, 2025 19:09
@lucasssvaz lucasssvaz added the Area: BLE Issues related to BLE label Nov 3, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2025

Messages
📖 🎉 Good Job! All checks are passing!

👋 Hello lucasssvaz, we appreciate your contribution to this project!


📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more.

🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project.

Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against b062cc8

@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2025

Test Results

 76 files   76 suites   14m 19s ⏱️
 38 tests  38 ✅ 0 💤 0 ❌
241 runs  241 ✅ 0 💤 0 ❌

Results for commit b062cc8.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2025

Memory usage test (comparing PR against master branch)

The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.

MemoryFLASH [bytes]FLASH [%]RAM [bytes]RAM [%]
TargetDECINCDECINCDECINCDECINC
ESP32C50⚠️ +7600.00⚠️ +0.09000.000.00
ESP32P40⚠️ +10300.00⚠️ +0.12💚 -16⚠️ +56💚 -0.05⚠️ +0.17
ESP32S30⚠️ +3640.00⚠️ +0.06💚 -160💚 -0.050.00
ESP32C30⚠️ +2780.00⚠️ +0.04000.000.00
ESP32C60⚠️ +7100.00⚠️ +0.100⚠️ +160.00⚠️ +0.07
ESP32H20⚠️ +7440.00⚠️ +0.10000.000.00
ESP320⚠️ +13920.00⚠️ +0.130⚠️ +160.00⚠️ +0.04
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32C5ESP32P4ESP32S3ESP32C3ESP32C6ESP32H2ESP32
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
libraries/BLE/examples/Beacon_Scanner⚠️ +7100⚠️ +9040⚠️ +3160⚠️ +2280⚠️ +660⚠️ +16⚠️ +6940⚠️ +1352⚠️ +16
libraries/BLE/examples/Client⚠️ +7600⚠️ +1026⚠️ +48⚠️ +3480⚠️ +2780⚠️ +710⚠️ +16⚠️ +7440⚠️ +13680
libraries/BLE/examples/Client_multiconnect--------------
libraries/BLE/examples/Client_secure_static_passkey⚠️ +7560⚠️ +1030⚠️ +56⚠️ +3640⚠️ +2740⚠️ +706⚠️ +16⚠️ +7400⚠️ +1392⚠️ +16
libraries/BLE/examples/EddystoneTLM_Beacon⚠️ +7100⚠️ +920💚 -16⚠️ +3160⚠️ +2280⚠️ +660⚠️ +16⚠️ +6940⚠️ +13800
libraries/BLE/examples/EddystoneURL_Beacon⚠️ +7100⚠️ +9200⚠️ +3160⚠️ +2280⚠️ +660⚠️ +16⚠️ +6940⚠️ +13520
libraries/BLE/examples/Notify⚠️ +7100⚠️ +9100⚠️ +284💚 -16⚠️ +2280⚠️ +660⚠️ +16⚠️ +6940⚠️ +13360
libraries/BLE/examples/Scan⚠️ +7100⚠️ +9120⚠️ +3040⚠️ +2280⚠️ +660⚠️ +16⚠️ +6940⚠️ +1356⚠️ +16
libraries/BLE/examples/Server⚠️ +7100⚠️ +910💚 -16⚠️ +300💚 -16⚠️ +2280⚠️ +660⚠️ +16⚠️ +6940⚠️ +13360
libraries/BLE/examples/Server_multiconnect⚠️ +7100⚠️ +9180⚠️ +300💚 -16⚠️ +2280⚠️ +660⚠️ +16⚠️ +6940⚠️ +13520
libraries/BLE/examples/Server_secure_authorization⚠️ +7100--⚠️ +3000⚠️ +2280⚠️ +660⚠️ +16⚠️ +6940--
libraries/BLE/examples/Server_secure_static_passkey⚠️ +7100⚠️ +9180⚠️ +300💚 -16⚠️ +2280⚠️ +660⚠️ +16⚠️ +6940⚠️ +1360⚠️ +16
libraries/BLE/examples/UART⚠️ +7100⚠️ +9180⚠️ +300💚 -16⚠️ +2280⚠️ +660⚠️ +16⚠️ +6940⚠️ +13560
libraries/BLE/examples/Write⚠️ +7100⚠️ +918💚 -16⚠️ +300💚 -16⚠️ +2280⚠️ +660⚠️ +16⚠️ +6940⚠️ +13400
libraries/BLE/examples/iBeacon⚠️ +7100⚠️ +9180⚠️ +300💚 -16⚠️ +2280⚠️ +660⚠️ +16⚠️ +6940⚠️ +13360

Copy link
Collaborator

@SuGlider SuGlider left a comment

Choose a reason for hiding this comment

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

All good! Thanks @lucasssvaz

@SuGlider SuGlider requested a review from Copilot November 4, 2025 05:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements lazy loading of BLE descriptors for NimBLE to avoid deadlock issues during characteristic construction and adds a new multi-connection client example.

Key changes:

  • Removed m_endHandle from BLERemoteCharacteristic and replaced with getRemoteService()->getEndHandle() calls
  • Implemented lazy loading of descriptors in getDescriptors(), getDescriptor(), and setNotify() methods
  • Added a new Client_multiconnect example demonstrating simultaneous connections to multiple BLE servers

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
libraries/BLE/src/BLERemoteCharacteristic.h Removed unused m_endHandle member variable from NimBLE implementation
libraries/BLE/src/BLERemoteCharacteristic.cpp Implemented lazy descriptor loading and replaced m_endHandle with service's end handle
libraries/BLE/examples/Client_multiconnect/ci.yml Added CI configuration for the new multi-connection example
libraries/BLE/examples/Client_multiconnect/Client_multiconnect.ino Added new example demonstrating multi-server BLE client connections

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lucasssvaz lucasssvaz force-pushed the feat/client_multiconnect branch from ffa08d4 to d0d84b7 Compare November 4, 2025 14:00
@lucasssvaz lucasssvaz requested a review from me-no-dev November 4, 2025 14:02
@me-no-dev me-no-dev added the Status: Pending Merge Pull Request is ready to be merged label Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: BLE Issues related to BLE Status: Pending Merge Pull Request is ready to be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BLE multi-connect example Ble Client connect multi Server

3 participants