From 90ab22555d5998fe84961d734ac0be134d438f08 Mon Sep 17 00:00:00 2001 From: h2zero <32826625+h2zero@users.noreply.github.com> Date: Sun, 14 May 2023 15:40:51 -0600 Subject: [PATCH] Set service handle in getHandle function if not set already. (#544) If a service has been created and started but not yet added to the gatt server then the call to getHandle will result in an invalid handle. This adds a call to set the handle value in the getHandle function. --- src/NimBLEService.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/NimBLEService.cpp b/src/NimBLEService.cpp index de94f8f7..8ee48a17 100644 --- a/src/NimBLEService.cpp +++ b/src/NimBLEService.cpp @@ -247,6 +247,9 @@ bool NimBLEService::start() { * @return The handle associated with this service. */ uint16_t NimBLEService::getHandle() { + if (m_handle == NULL_HANDLE) { + ble_gatts_find_svc(&getUUID().getNative()->u, &m_handle); + } return m_handle; } // getHandle