Skip to content

fix(ble): Fix onRead callback#12234

Merged
me-no-dev merged 1 commit into
espressif:masterfrom
lucasssvaz:fix/onread
Jan 13, 2026
Merged

fix(ble): Fix onRead callback#12234
me-no-dev merged 1 commit into
espressif:masterfrom
lucasssvaz:fix/onread

Conversation

@lucasssvaz
Copy link
Copy Markdown
Member

Description of Change

This pull request updates the logic for handling GATT server read events in both BLECharacteristic and BLEDescriptor to ensure that the onRead() callback is only called for the initial read request, and not for follow-up packets during long reads. This prevents unnecessary repeated callbacks and makes the behavior more robust.

Improvements to GATT read event handling:

  • Updated BLECharacteristic::handleGATTServerEvent to call onRead() only if the buffer length is greater than 0 and the connection handle is valid, ensuring callbacks are not triggered for follow-up packets in long reads.
  • Updated BLEDescriptor::handleGATTServerEvent to use the same logic, only calling onRead() for the initial read request and not for follow-up packets, by checking buffer length and connection handle validity.

Test Scenarios

Tested locally

Related links

Fixes #12198

@lucasssvaz lucasssvaz self-assigned this Jan 13, 2026
@lucasssvaz lucasssvaz requested a review from SuGlider as a code owner January 13, 2026 12:48
@lucasssvaz lucasssvaz added the Area: BLE Issues related to BLE label Jan 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 13, 2026

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 f8e0947

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 13, 2026

Test Results

 90 files   90 suites   33m 8s ⏱️
 67 tests  62 ✅ 0 💤 5 ❌
751 runs  745 ✅ 0 💤 6 ❌

For more details on these failures, see this check.

Results for commit f8e0947.

♻️ This comment has been updated with latest results.

@lucasssvaz lucasssvaz added the Status: Review needed Issue or PR is awaiting review label Jan 13, 2026
@P-R-O-C-H-Y
Copy link
Copy Markdown
Member

LGTM, CI is failing due to unused variable.

@lucasssvaz
Copy link
Copy Markdown
Member Author

LGTM, CI is failing due to unused variable.

Fixed, thanks!

@github-actions
Copy link
Copy Markdown
Contributor

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
ESP32000.000.00000.000.00
ESP32C3💚 -2720💚 -0.040.00000.000.00
ESP32C5000.000.00000.000.00
ESP32C6000.000.00000.000.00
ESP32H2💚 -2700💚 -0.040.00000.000.00
ESP32P4💚 -2700💚 -0.030.00000.000.00
ESP32S3💚 -2760💚 -0.050.00000.000.00
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32ESP32C3ESP32C5ESP32C6ESP32H2ESP32P4ESP32S3
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
libraries/BLE/examples/Beacon_Scanner00💚 -2680----💚 -2680💚 -2680💚 -2760
libraries/BLE/examples/Client00💚 -2620----💚 -2620💚 -2620💚 -2400
libraries/BLE/examples/Client_Server00💚 -2620----💚 -2620💚 -2620--
libraries/BLE/examples/Client_multiconnect00💚 -2620----💚 -2620💚 -2620--
libraries/BLE/examples/Client_secure_static_passkey00💚 -2620----💚 -2620💚 -2620--
libraries/BLE/examples/EddystoneTLM_Beacon00💚 -2700----💚 -2700💚 -2700--
libraries/BLE/examples/EddystoneURL_Beacon00💚 -2700----💚 -2700💚 -2700--
libraries/BLE/examples/Notify00💚 -2640----💚 -2620💚 -2620--
libraries/BLE/examples/Scan00💚 -2680----💚 -2680💚 -2680--
libraries/BLE/examples/Server00💚 -2700----💚 -2680💚 -2680--
libraries/BLE/examples/Server_multiconnect00💚 -2640----💚 -2620💚 -2620--
libraries/BLE/examples/Server_secure_static_passkey00💚 -2720----💚 -2700💚 -2700--
libraries/BLE/examples/UART00💚 -2620----💚 -2620💚 -2640--
libraries/BLE/examples/Write00💚 -2700----💚 -2680💚 -2680--
libraries/BLE/examples/iBeacon00💚 -2620----💚 -2620💚 -2620--
libraries/BLE/examples/Server_secure_authorization--💚 -2640----💚 -2640----

@lucasssvaz lucasssvaz added Status: Pending Merge Pull Request is ready to be merged and removed Status: Review needed Issue or PR is awaiting review labels Jan 13, 2026
@me-no-dev me-no-dev merged commit 03a6f9a into espressif:master Jan 13, 2026
98 of 102 checks passed
@lucasssvaz lucasssvaz deleted the fix/onread branch January 14, 2026 14:58
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.

BLECharacteristic onRead() callbacks never run on NimBLE

4 participants