fix: Add debug logging and accept RSSI -127 from BlueZ

Fixes critical discovery issues caused by BlueZ/Bleak limitations.

Root cause analysis (via nRF Connect + debug logging):
1. Bleak doesn't parse service UUIDs from advertisement data (service_uuids=[])
   despite UUIDs being present (verified with nRF Connect showing correct UUID)
2. Name-based fallback works but RSSI -127 caused rejection
3. BlueZ hides connected/known devices from scan results

Changes:
- Added debug logging to detection_callback to diagnose Bleak data parsing
- Accept RSSI -127 as valid (BlueZ sentinel for "RSSI unknown")
- Confirmed name fallback pattern (RNS-*) works when service UUID fails

Test results:
- nRF Connect confirms correct UUID in advertisement: 37145b00-442d-4a94-917f-8f42c5da28e3
- Bleak sees device name "RNS-Pi1" but service_uuids=[]
- After bluetoothctl remove + RSSI fix: discovered via name pattern
- Asymmetric success: Pi 1→Pi 2 peer interface spawned, 72 bytes transmitted

Known issues:
- Bleak/BlueZ doesn't populate service_uuids from advertisement (Linux limitation)
- BlueZ auto-reconnects and hides devices from scans (requires bluetoothctl remove)
- Asymmetric discovery due to scan-hiding issue

Related: BLE_TEST_RESULTS_2025_10_31.md, BLE_DISCOVERY_TROUBLESHOOTING.md
This commit is contained in:
torlando-tech 2025-10-31 15:08:20 -04:00
commit d11c73a3fd

View file

@ -898,6 +898,10 @@ class BLEInterface(Interface):
def detection_callback(device, advertisement_data):
"""Callback invoked for each discovered BLE device."""
# Debug: Log ALL devices to diagnose why matching fails
RNS.log(f"{self} DEBUG: Device {device.address} name={device.name} "
f"service_uuids={advertisement_data.service_uuids} "
f"local_name={advertisement_data.local_name}", RNS.LOG_DEBUG)
discovered_devices.append((device, advertisement_data))
# Scan duration based on power mode
@ -976,7 +980,9 @@ class BLEInterface(Interface):
RNS.log(f"{self} found matching peer {device_name} ({device.address}) via {match_method}, "
f"RSSI: {rssi}dBm (min: {self.min_rssi}dBm)", RNS.LOG_DEBUG)
if rssi >= self.min_rssi:
# Accept if RSSI meets minimum OR is -127 (BlueZ sentinel for "unknown")
# -127 means BlueZ doesn't have RSSI data, but device is discoverable
if rssi >= self.min_rssi or rssi == -127:
# Create or update DiscoveredPeer
if device.address in self.discovered_peers:
# Update existing peer's RSSI and timestamp