From 099ab06b9243d2427f3c406c275041b8f196aeb5 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Oct 2025 16:59:49 -0500 Subject: [PATCH] Add check for connected state in NimBLE onRead() --- src/nimble/NimbleBluetooth.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp index beeeb63b4..9accf23c6 100644 --- a/src/nimble/NimbleBluetooth.cpp +++ b/src/nimble/NimbleBluetooth.cpp @@ -466,6 +466,10 @@ class NimbleBluetoothFromRadioCallback : public NimBLECharacteristicCallbacks virtual void onRead(NimBLECharacteristic *pCharacteristic) #endif { + // In some cases, it seems a new connection starts with a read. + // The API has no bytes to send, leading to a timeout. This short-circuits this problem. + if (!bluetoothPhoneAPI->isConnected()) + return; // CAUTION: This callback runs in the NimBLE task!!! Don't do anything except communicate with the main task's runOnce. int currentReadCount = bluetoothPhoneAPI->readCount.fetch_add(1);