From e93f943cc4503261f497051fbde557dc41a7f316 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. 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 b124fcb..0ae2e9f 100644 --- a/src/NimBLEService.cpp +++ b/src/NimBLEService.cpp @@ -248,6 +248,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