From 1968a009dd21303f6c5979bab21287e99dd4102b Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 23 Sep 2025 07:31:25 -0500 Subject: [PATCH] Clear lasttoradio on BLE disconnect (#8095) * On disconnect, clear the lastToRadio buffer * Move it, bucko! --- src/nimble/NimbleBluetooth.cpp | 3 +++ src/platform/nrf52/NRF52Bluetooth.cpp | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp index 13446be45..0c4e30785 100644 --- a/src/nimble/NimbleBluetooth.cpp +++ b/src/nimble/NimbleBluetooth.cpp @@ -247,6 +247,9 @@ class NimbleBluetoothServerCallback : public NimBLEServerCallbacks bluetoothPhoneAPI->numBytes = 0; bluetoothPhoneAPI->queue_size = 0; } + + // Clear the last ToRadio packet buffer to avoid rejecting first packet from new connection + memset(lastToRadio, 0, sizeof(lastToRadio)); #ifdef NIMBLE_TWO // Restart Advertising ble->startAdvertising(); diff --git a/src/platform/nrf52/NRF52Bluetooth.cpp b/src/platform/nrf52/NRF52Bluetooth.cpp index f8366ae32..b457c35b7 100644 --- a/src/platform/nrf52/NRF52Bluetooth.cpp +++ b/src/platform/nrf52/NRF52Bluetooth.cpp @@ -28,6 +28,9 @@ static BLEDfuSecure bledfusecure; // static uint8_t fromRadioBytes[meshtastic_FromRadio_size]; static uint8_t toRadioBytes[meshtastic_ToRadio_size]; +// Last ToRadio value received from the phone +static uint8_t lastToRadio[MAX_TO_FROM_RADIO_SIZE]; + static uint16_t connectionHandle; class BluetoothPhoneAPI : public PhoneAPI @@ -74,6 +77,9 @@ void onDisconnect(uint16_t conn_handle, uint8_t reason) bluetoothPhoneAPI->close(); } + // Clear the last ToRadio packet buffer to avoid rejecting first packet from new connection + memset(lastToRadio, 0, sizeof(lastToRadio)); + // Notify UI (or any other interested firmware components) meshtastic::BluetoothStatus newStatus(meshtastic::BluetoothStatus::ConnectionState::DISCONNECTED); bluetoothStatus->updateStatus(&newStatus); @@ -145,8 +151,6 @@ void onFromRadioAuthorize(uint16_t conn_hdl, BLECharacteristic *chr, ble_gatts_e } authorizeRead(conn_hdl); } -// Last ToRadio value received from the phone -static uint8_t lastToRadio[MAX_TO_FROM_RADIO_SIZE]; void onToRadioWrite(uint16_t conn_hdl, BLECharacteristic *chr, uint8_t *data, uint16_t len) {