From cc4fd51c88cd43692a0eae15fdf199c95b240542 Mon Sep 17 00:00:00 2001 From: phaseloop Date: Wed, 10 Dec 2025 10:30:35 +0000 Subject: [PATCH] fix potential connectivity issues --- src/platform/nrf52/NRF52Bluetooth.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/platform/nrf52/NRF52Bluetooth.cpp b/src/platform/nrf52/NRF52Bluetooth.cpp index d620d0fda..5562b5cc2 100644 --- a/src/platform/nrf52/NRF52Bluetooth.cpp +++ b/src/platform/nrf52/NRF52Bluetooth.cpp @@ -64,6 +64,10 @@ void onConnect(uint16_t conn_handle) connection->getPeerName(central_name, sizeof(central_name)); LOG_INFO("BLE Connected to %s", central_name); + // Clear the last ToRadio packet buffer to avoid rejecting first packet from new connection + // This is done onConnect too because we suspect in some cases onDisconnect callback may be missing + memset(lastToRadio, 0, sizeof(lastToRadio)); + // negotiate connections params as soon as possible // some phones and laptops seem to ignore GAP preferred settings and treat slave latency as connection disruption // such devices can not connect to the node. This is fixed by forcing parameter negotiation at the start of communication @@ -76,7 +80,12 @@ void onConnect(uint16_t conn_handle) newParams.slave_latency = 5; newParams.conn_sup_timeout = 400; // in 10 ms units, timeout 4s - sd_ble_gap_conn_param_update(conn_handle, &newParams); + int ret = sd_ble_gap_conn_param_update(conn_handle, &newParams); + + if(ret != NRF_SUCCESS){ + LOG_INFO("BLE connection parameter negotiation failed. Error code: %x", ret); + + } // Notify UI (or any other interested firmware components) meshtastic::BluetoothStatus newStatus(meshtastic::BluetoothStatus::ConnectionState::CONNECTED); @@ -293,7 +302,7 @@ void NRF52Bluetooth::setup() // Attention! Same values - latency and intervals (if added here) must also be negotiated inside onConnect method. See comments there. - Bluefruit.Periph.setConnSlaveLatency(5); + // Bluefruit.Periph.setConnSlaveLatency(5); // min, max connection intervals are negotiated in onConnect as (24,40) [in 1.25 ms units] -> (30, 50) milliseconds.