NRF52 BLE fixes / tweaks (#7152)

* Try-fix: Flaky NRF52 bluetooth pairing for some users

* Safe access for screen pointer
This commit is contained in:
Ben Meadors 2025-06-27 06:26:34 -05:00 committed by GitHub
parent 29e7a71c97
commit 2b97576b18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -314,7 +314,9 @@ void NRF52Bluetooth::onConnectionSecured(uint16_t conn_handle)
}
bool NRF52Bluetooth::onPairingPasskey(uint16_t conn_handle, uint8_t const passkey[6], bool match_request)
{
LOG_INFO("BLE pair process started with passkey %.3s %.3s", passkey, passkey + 3);
char passkey1[4] = {passkey[0], passkey[1], passkey[2], '\0'};
char passkey2[4] = {passkey[3], passkey[4], passkey[5], '\0'};
LOG_INFO("BLE pair process started with passkey %s %s", passkey1, passkey2);
powerFSM.trigger(EVENT_BLUETOOTH_PAIR);
// Get passkey as string
@ -327,6 +329,7 @@ bool NRF52Bluetooth::onPairingPasskey(uint16_t conn_handle, uint8_t const passke
bluetoothStatus->updateStatus(new meshtastic::BluetoothStatus(textkey));
#if !defined(MESHTASTIC_EXCLUDE_SCREEN) // Todo: migrate this display code back into Screen class, and observe bluetoothStatus
if (screen) {
screen->startAlert([](OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) -> void {
char btPIN[16] = "888888";
snprintf(btPIN, sizeof(btPIN), "%06u", configuredPasskey);
@ -352,6 +355,7 @@ bool NRF52Bluetooth::onPairingPasskey(uint16_t conn_handle, uint8_t const passke
y_offset = display->height() == 64 ? y_offset + FONT_HEIGHT_LARGE - 6 : y_offset + FONT_HEIGHT_LARGE + 5;
display->drawString(x_offset + x, y_offset + y, deviceName);
});
}
#endif
if (match_request) {
uint32_t start_time = millis();
@ -394,8 +398,7 @@ void NRF52Bluetooth::onPairingCompleted(uint16_t conn_handle, uint8_t auth_statu
{
if (auth_status == BLE_GAP_SEC_STATUS_SUCCESS) {
LOG_INFO("BLE pair success");
bluetoothStatus->updateStatus(
new meshtastic::BluetoothStatus(meshtastic::BluetoothStatus::ConnectionState::DISCONNECTED));
bluetoothStatus->updateStatus(new meshtastic::BluetoothStatus(meshtastic::BluetoothStatus::ConnectionState::CONNECTED));
} else {
LOG_INFO("BLE pair failed");
// Notify UI (or any other interested firmware components)
@ -404,7 +407,9 @@ void NRF52Bluetooth::onPairingCompleted(uint16_t conn_handle, uint8_t auth_statu
}
// Todo: migrate this display code back into Screen class, and observe bluetoothStatus
if (screen) {
screen->endAlert();
}
}
void NRF52Bluetooth::sendLog(const uint8_t *logMessage, size_t length)