Skip to content

Conversation

@h2zero
Copy link
Owner

@h2zero h2zero commented Oct 30, 2025

This refactors the handling of sending notifications and indications for greater efficiency.

  • Adds client subscription state tracking to NimBLECharacteristic rather than relying on the stack.
  • Notifications/indications are now sent directly, no longer calling the callback to read the values. This avoids delays and flash writes in the stack, allowing for greater throughput.
  • Notifications will now wait up to 10ms if buffers are full to reattempt transmission before failing.
  • Adds a new overloaded callback to NimBLECharacteristicCallbacks for the notification/indication onStatus method that provides a NimBLEConnInfo reference.

@h2zero h2zero force-pushed the refactor-notify branch 2 times, most recently from 47a5a55 to f07e777 Compare October 31, 2025 20:49
@h2zero h2zero requested a review from Copilot November 18, 2025 00:28
Copilot finished reviewing on behalf of h2zero November 18, 2025 00:30
Copy link

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 refactors the notification and indication handling in NimBLE to improve efficiency and throughput by tracking client subscription state locally and sending data directly rather than relying on the stack to read values.

Key Changes

  • Adds client subscription state tracking via SubPeerEntry structure in NimBLECharacteristic with flags for subscription type and security status
  • Refactors sendValue() to send notifications/indications directly using copied data with retry logic (up to 10ms) for buffer allocation failures
  • Introduces new getCharacteristicByHandle() lookup method and streamlines event handling in NimBLEServer for subscribe and notify_tx events

Reviewed Changes

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

File Description
src/NimBLEServer.h Adds getCharacteristicByHandle() method declaration and reorganizes private method declarations
src/NimBLEServer.cpp Implements characteristic lookup, fixes typo and bug in getPeerInfo(), refactors subscribe/notify_tx event handling to use new subscription tracking
src/NimBLECharacteristic.h Defines SubPeerEntry struct for tracking subscriber state, adds subscription management methods, and new onStatus() callback overload with NimBLEConnInfo
src/NimBLECharacteristic.cpp Refactors notify/indicate to send data directly, implements subscription request processing and peer status updates with critical section protection

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

This refactors the handling of sending notifications and indications for greater efficiency.
* Adds client subscription state tracking to NimBLECharacteristic rather than relying on the stack.
* Notifications/indications are now sent directly, no longer calling the callback to read the values.
  This avoids delays and flash writes in the stack, allowing for greater throughput.
Adds a new overloaded callback to NimBLECharacteristicCallbacks for the notification/indication onStatus method that provides a NimBLEConnInfo reference.
@h2zero h2zero merged commit f216e95 into master Nov 18, 2025
71 checks passed
@h2zero h2zero deleted the refactor-notify branch November 18, 2025 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants