From 6ea4613b4bb8b577f730d5ca49f4885a152d45e5 Mon Sep 17 00:00:00 2001 From: h2zero Date: Sun, 14 May 2023 12:26:05 -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 and 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