Skip to content

Add compile-time version macros and NimBLEDevice::getVersion() to NimBLECppVersion.h#1118

Merged
h2zero merged 1 commit intomasterfrom
copilot/autodetect-nimble-arduino-version
Mar 17, 2026
Merged

Add compile-time version macros and NimBLEDevice::getVersion() to NimBLECppVersion.h#1118
h2zero merged 1 commit intomasterfrom
copilot/autodetect-nimble-arduino-version

Conversation

Copy link
Contributor

Copilot AI commented Mar 17, 2026

No standard mechanism existed to detect NimBLE-Arduino version at compile-time (e.g. to differentiate v1 vs v2) or query it at runtime.

Changes

  • New src/NimBLECppVersion.h — standalone header (no BLE stack dependency) providing:

    • NIMBLE_CPP_VERSION_MAJOR / _MINOR / _PATCH — individual component macros
    • NIMBLE_CPP_VERSION_VAL(major, minor, patch) — constructs a comparable integer
    • NIMBLE_CPP_VERSION — current version as a single integer for #if guards
    • NIMBLE_CPP_VERSION_STR — version string derived via stringification from the component macros (no hardcoded duplicate)
  • src/NimBLEDevice.h — includes NimBLECppVersion.h outside the CONFIG_BT_NIMBLE_ENABLED guard so version info is always available regardless of BLE stack configuration, and declares static const char* getVersion()

  • src/NimBLEDevice.cpp — implements NimBLEDevice::getVersion() returning the version string at runtime

Usage

// Compile-time v1/v2 detection
#if NIMBLE_CPP_VERSION >= NIMBLE_CPP_VERSION_VAL(2, 0, 0)
    // NimBLE-Arduino v2+ API
#else
    // NimBLE-Arduino v1 API
#endif

// Runtime query
Serial.println(NimBLEDevice::getVersion()); // "2.3.8"
Original prompt

This section details on the original issue you should resolve

<issue_title>Autodetection if NimBLE-Arduino v1 or v2 is used</issue_title>
<issue_description>I'm working on automatic BLE library detection in ArduinoBleOTA library https://github.com/vovagorodok/ArduinoBleOTA/blob/main/src/BleOtaDefines.h

#if __has_include("ArduinoBLE.h")
    #include <ArduinoBLE.h>
    #define BLE_OTA_BLE_LIB_ARDUINO_BLE
    #define BLE_OTA_LIB_ARDUINO_BLE
#elif __has_include("NimBLEDevice.h")
    #include <NimBLEDevice.h>
    #define BLE_OTA_BLE_LIB_NIM_BLE_ARDUINO
    #define BLE_OTA_LIB_NIM_BLE_ARDUINO
#elif defined(ARDUINO_ARCH_ESP32)
    #include <BLEDevice.h>
    #define BLE_OTA_BLE_LIB_ESP32
    #define BLE_OTA_LIB_ESP32
#else
    #error "Unsupported BLE library. Consider ArduinoBLE or NimBLE-Arduino."
#endif

What is the best way to detect if NimBLE-Arduino v1 or v2 is used? Here is some macro that define library version? Or some files that are not in v1 and are in v2 (and will be available all the time)?</issue_description>

<agent_instructions>Create a PR to include a version macro and callable functions to use in runtime
</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@h2zero You could probably use `#ifdef CONFIG_NIMBLE_CPP_DEBUG_ASSERT_ENABLED` as that was added in 2.x @h2zero Yes, I was contemplating this some time ago, just haven't implemented it yet @h2zero >Notice that __has_include doesn't work correctly in ArduinoIDE. PlatformIO handles it better

I did not know this, I see it is used in the core as well so I would expect it to work fine? </comment_new>


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI changed the title [WIP] Add autodetection for NimBLE-Arduino v1 or v2 Add compile-time version macros and runtime version function to NimBLEVersions.h Mar 17, 2026
Copilot AI requested a review from h2zero March 17, 2026 19:08
Copilot AI changed the title Add compile-time version macros and runtime version function to NimBLEVersions.h Add compile-time version macros and NimBLEDevice::getNimbleVersion() to NimBLEVersion.h Mar 17, 2026
Copilot AI requested a review from h2zero March 17, 2026 19:25
Copilot AI changed the title Add compile-time version macros and NimBLEDevice::getNimbleVersion() to NimBLEVersion.h Add compile-time version macros and NimBLEDevice::getVersion() to NimBLEVersion.h Mar 17, 2026
Copilot AI requested a review from h2zero March 17, 2026 19:28
Copilot AI changed the title Add compile-time version macros and NimBLEDevice::getVersion() to NimBLEVersion.h Add compile-time version macros and NimBLEDevice::getVersion() to NimBLECppVersion.h Mar 17, 2026
Copilot AI requested a review from h2zero March 17, 2026 19:40
Copy link
Owner

@h2zero h2zero left a comment

Choose a reason for hiding this comment

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

LGTM

@h2zero h2zero marked this pull request as ready for review March 17, 2026 19:47
@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9d73e610-070e-4945-a4a9-15c25743ee4c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch copilot/autodetect-nimble-arduino-version
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@h2zero h2zero force-pushed the copilot/autodetect-nimble-arduino-version branch 3 times, most recently from 13422b2 to 58a7ebe Compare March 17, 2026 20:18
Co-authored-by: h2zero <32826625+h2zero@users.noreply.github.com>
@h2zero h2zero force-pushed the copilot/autodetect-nimble-arduino-version branch from 58a7ebe to fd55307 Compare March 17, 2026 20:30
@h2zero h2zero merged commit 3ce11f0 into master Mar 17, 2026
42 checks passed
@h2zero h2zero deleted the copilot/autodetect-nimble-arduino-version branch March 17, 2026 20:46
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.

Autodetection if NimBLE-Arduino v1 or v2 is used

2 participants