Conversation
…imBLEClientCallbacks Co-authored-by: h2zero <32826625+h2zero@users.noreply.github.com>
* [Bugfix] NimBLEDevice::createServer can crash if stack not initialized. This removes the gatts/gap reset calls from NimBLEDevice::createServer so that it can be safely used before initializing the stack. This also deprecates NimBLEService::start the the services will now be added/created only when the server is started.
Co-authored-by: h2zero <32826625+h2zero@users.noreply.github.com>
📝 WalkthroughWalkthroughArrr, this PR be restructurin' how NimBLE services be startin' themselves, matey! The swashbuckling changes remove explicit service start calls from examples and library code, add proper error handlin' for GATT server startup, introduce version macros for trackin' library releases, add new passkey display callbacks for pairing flows, and refactor service startup to flow through the server instead o' bein' called independently. Yarrr! Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes This PR be involvin' scattered changes across multiple files with mixed complexity, matey. Ye be havin' return-type signature changes in Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/NimBLEServer.cpp (1)
272-320:⚠️ Potential issue | 🔴 CriticalAhoy! Critical issue spotted in yer extended advertising, ye salty sea dog!
While the
start()return value changes be sound, not all callers be handlin' the new boolean properly! The extended advertising be ignorin' the return value atsrc/NimBLEExtAdvertising.cpp:74:pServer->start(); // make sure the GATT server is ready before advertisingThis be sailin' blind! Contrast with
src/NimBLEAdvertising.cpp:200, which handles it proper-like:if (pServer != nullptr && !pServer->start()) { // make sure the GATT server is ready before advertising NIMBLE_LOGE(LOG_TAG, "Failed to start GATT server"); return false; }Extended advertising must check the return value and handle failure before proceeding with configuration. The GATT server could be sinkin' without ye knowin' it!
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/NimBLEServer.cpp` around lines 272 - 320, The call to pServer->start() in NimBLEExtAdvertising (where extended advertising prepares to start) ignores the boolean return and can proceed when GATT start failed; update the logic around the call in NimBLEExtAdvertising.cpp (the spot currently calling pServer->start() to "make sure the GATT server is ready") to mirror NimBLEAdvertising.cpp's pattern: check pServer != nullptr and if pServer->start() returns false, log an error via NIMBLE_LOGE (similar message "Failed to start GATT server") and return false from the extended advertising start/config routine so advertising setup is aborted on GATT start failure.
🧹 Nitpick comments (1)
src/NimBLEClient.cpp (1)
1213-1222: Ahoy! The magic number 123456 be sailin' through yer code, matey!Arr, this passkey check be usin' the hardcoded value
123456to determine whether to invoke the callback. While this be consistent with the server-side implementation inNimBLEServer.cpp(lines 668-669), it be a bit fragile, ye scurvy dog! If a landlubber intentionally sets their passkey to 123456, the callback will still be invoked unnecessarily.Consider definin' a named constant like
NIMBLE_DEFAULT_PASSKEYto make the intent clearer across the seven seas of yer codebase.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/NimBLEClient.cpp` around lines 1213 - 1222, Replace the magic literal 123456 used in the BLE_SM_IOACT_DISP handling with a named constant (e.g., NIMBLE_DEFAULT_PASSKEY) to make intent explicit and avoid accidental collisions; declare NIMBLE_DEFAULT_PASSKEY in an appropriate shared header or at the top of NimBLEClient.cpp and update the check in the BLE_SM_IOACT_DISP branch where pkey.passkey (from NimBLEDevice::getSecurityPasskey()) is compared and used to decide whether to call pClient->m_pClientCallbacks->onPassKeyDisplay(peerInfo) so the same symbolic constant is used consistently with the server-side implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/NimBLEService.h`:
- Around line 45-51: The deprecated NimBLEService::start() currently returns
true unconditionally which hides real startup failures; update this shim to call
and return the actual boolean result from the server start routine instead of
always true — locate NimBLEService::start() and change it to invoke
NimBLEServer::start() (or the appropriate server instance/owner start method
tied to this service) and return that boolean so existing service->start() call
sites reflect real success/failure.
---
Outside diff comments:
In `@src/NimBLEServer.cpp`:
- Around line 272-320: The call to pServer->start() in NimBLEExtAdvertising
(where extended advertising prepares to start) ignores the boolean return and
can proceed when GATT start failed; update the logic around the call in
NimBLEExtAdvertising.cpp (the spot currently calling pServer->start() to "make
sure the GATT server is ready") to mirror NimBLEAdvertising.cpp's pattern: check
pServer != nullptr and if pServer->start() returns false, log an error via
NIMBLE_LOGE (similar message "Failed to start GATT server") and return false
from the extended advertising start/config routine so advertising setup is
aborted on GATT start failure.
---
Nitpick comments:
In `@src/NimBLEClient.cpp`:
- Around line 1213-1222: Replace the magic literal 123456 used in the
BLE_SM_IOACT_DISP handling with a named constant (e.g., NIMBLE_DEFAULT_PASSKEY)
to make intent explicit and avoid accidental collisions; declare
NIMBLE_DEFAULT_PASSKEY in an appropriate shared header or at the top of
NimBLEClient.cpp and update the check in the BLE_SM_IOACT_DISP branch where
pkey.passkey (from NimBLEDevice::getSecurityPasskey()) is compared and used to
decide whether to call pClient->m_pClientCallbacks->onPassKeyDisplay(peerInfo)
so the same symbolic constant is used consistently with the server-side
implementation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: aad66044-0c59-4978-b924-2e3a2aee33a5
📒 Files selected for processing (14)
examples/Bluetooth_5/NimBLE_extended_server/main/main.cppexamples/Bluetooth_5/NimBLE_multi_advertiser/main/main.cppexamples/NimBLE_Server/main/main.cppsrc/NimBLEAdvertising.cppsrc/NimBLEClient.cppsrc/NimBLEClient.hsrc/NimBLECppVersion.hsrc/NimBLEDevice.cppsrc/NimBLEDevice.hsrc/NimBLEServer.cppsrc/NimBLEServer.hsrc/NimBLEService.cppsrc/NimBLEService.hsrc/NimBLEStream.cpp
💤 Files with no reviewable changes (3)
- examples/Bluetooth_5/NimBLE_multi_advertiser/main/main.cpp
- examples/NimBLE_Server/main/main.cpp
- examples/Bluetooth_5/NimBLE_extended_server/main/main.cpp
Summary by CodeRabbit
Release Notes
New Features
getVersion()Bug Fixes
Chores