From fae7a8c9548598e8e064b65b85c1609e2e96a201 Mon Sep 17 00:00:00 2001 From: torlando-tech Date: Fri, 31 Oct 2025 15:08:20 -0400 Subject: [PATCH] fix: Add debug logging and accept RSSI -127 from BlueZ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/RNS/Interfaces/BLEInterface.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/RNS/Interfaces/BLEInterface.py b/src/RNS/Interfaces/BLEInterface.py index b61c952..9aab0f5 100644 --- a/src/RNS/Interfaces/BLEInterface.py +++ b/src/RNS/Interfaces/BLEInterface.py @@ -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