From 26b3ba3e8f0b24f59725e942fdd6c51fbf9f1e07 Mon Sep 17 00:00:00 2001 From: h2zero Date: Wed, 2 Sep 2020 12:05:05 -0600 Subject: [PATCH] Fix delayed advertising when first called. --- src/NimBLEAdvertising.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/NimBLEAdvertising.cpp b/src/NimBLEAdvertising.cpp index bdf1253..ee9789a 100644 --- a/src/NimBLEAdvertising.cpp +++ b/src/NimBLEAdvertising.cpp @@ -227,6 +227,11 @@ void NimBLEAdvertising::start() { if(pServer != nullptr) { if(!pServer->m_gattsStarted){ pServer->start(); + // When the server instance is created it resets GATT which + // seems to put the controller in a sleep loop? This causes a delay when + // advertising is started the first time. To avoid this we call ble_gap_adv_stop + // to get the controller ready. + ble_gap_adv_stop(); } else if(pServer->getConnectedCount() >= NIMBLE_MAX_CONNECTIONS) { NIMBLE_LOGW(LOG_TAG, "Max connections reached - not advertising"); return;