From 828e11cc482a802b3385c9a4aa7cb7b00a519360 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 8 Oct 2025 14:16:57 -0500 Subject: [PATCH] NimBLE speedup (#8281) * Remove status polling code in NimBLE * Goober --------- Co-authored-by: Jonathan Bennett --- src/mesh/PhoneAPI.cpp | 2 +- src/nimble/NimbleBluetooth.cpp | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index 210e0ba06..d2ed2d4cb 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -431,7 +431,6 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf) break; case STATE_SEND_OTHER_NODEINFOS: { - LOG_DEBUG("Send known nodes"); if (nodeInfoForPhone.num != 0) { // Just in case we stored a different user.id in the past, but should never happen going forward sprintf(nodeInfoForPhone.user.id, "!%08x", nodeInfoForPhone.num); @@ -592,6 +591,7 @@ bool PhoneAPI::available() nodeInfoForPhone.snr = isUs ? 0 : nodeInfoForPhone.snr; nodeInfoForPhone.via_mqtt = isUs ? false : nodeInfoForPhone.via_mqtt; nodeInfoForPhone.is_favorite = nodeInfoForPhone.is_favorite || isUs; // Our node is always a favorite + onNowHasData(0); } } diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp index 5524765f3..030e00d6b 100644 --- a/src/nimble/NimbleBluetooth.cpp +++ b/src/nimble/NimbleBluetooth.cpp @@ -120,14 +120,19 @@ class NimbleBluetoothFromRadioCallback : public NimBLECharacteristicCallbacks virtual void onRead(NimBLECharacteristic *pCharacteristic) #endif { - int tries = 0; - bluetoothPhoneAPI->phoneWants = true; - while (!bluetoothPhoneAPI->hasChecked && tries < 100) { - bluetoothPhoneAPI->setIntervalFromNow(0); - delay(20); - tries++; - } std::lock_guard guard(bluetoothPhoneAPI->nimble_mutex); + + // If we don't have fresh data, trigger a refresh + if (!bluetoothPhoneAPI->hasChecked || bluetoothPhoneAPI->numBytes == 0) { + bluetoothPhoneAPI->phoneWants = true; + bluetoothPhoneAPI->setIntervalFromNow(0); + + // Get fresh data immediately + bluetoothPhoneAPI->numBytes = bluetoothPhoneAPI->getFromRadio(bluetoothPhoneAPI->fromRadioBytes); + bluetoothPhoneAPI->hasChecked = true; + } + + // Set the characteristic value with whatever data we have pCharacteristic->setValue(bluetoothPhoneAPI->fromRadioBytes, bluetoothPhoneAPI->numBytes); if (bluetoothPhoneAPI->numBytes != 0) // if we did send something, queue it up right away to reload