BLE stability: host-controller resync, stuck GAP conn cancel, scan diagnostics

After a 574 connection failure, the NimBLE controller's scan state can
become corrupted (returning rc=530 / Invalid HCI Params) even after the
host re-syncs. This led to scan failure escalation and device reboots.

Key fixes:
- Add ble_gap_conn_cancel() to enterErrorRecovery() — stuck GAP master
  connection operations were blocking all subsequent scans
- Add ble_hs_sched_reset(BLE_HS_ECONTROLLER) in error recovery to force
  a full host-controller resynchronization after desync
- Proactively cancel stale GAP connections before scan start
- Reduce SCAN_FAIL_RECOVERY_THRESHOLD from 10 to 5 for faster recovery
- Enhanced scan failure logging with GAP state diagnostics
- Move ESP reset reason logging after WiFi init for UDP log visibility
- Suppress connection candidate log spam when at max connections

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
torlando-tech
2026-03-03 19:57:55 -05:00
parent 2cc9441f0a
commit 46ce057a1e
4 changed files with 70 additions and 34 deletions
+3 -3
View File
@@ -931,10 +931,10 @@ void BLEInterface::processDiscoveredPeers() {
last_peer_log = now;
}
if (candidate && candidate->mac_address.size() >= Limits::MAC_SIZE) {
if (candidate && candidate->mac_address.size() >= Limits::MAC_SIZE &&
_peer_manager.canAcceptConnection()) {
INFO("BLE: Connection candidate: " + BLEAddress(candidate->mac_address.data()).toString() +
" type=" + std::to_string(candidate->address_type) +
" canAccept=" + std::string(_peer_manager.canAcceptConnection() ? "yes" : "no"));
" type=" + std::to_string(candidate->address_type));
}
if (candidate && _peer_manager.canAcceptConnection()) {