From 48e182d1b10dfb1c9ec08e0a3c97b23e5656f0b5 Mon Sep 17 00:00:00 2001 From: Nikolas Saf Date: Mon, 2 Oct 2023 21:22:28 +0200 Subject: [PATCH] improve wifi SSID matching --- .../open_gopro/wifi/adapters/wireless.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/demos/python/sdk_wireless_camera_control/open_gopro/wifi/adapters/wireless.py b/demos/python/sdk_wireless_camera_control/open_gopro/wifi/adapters/wireless.py index 274d82b0..0285e3a3 100644 --- a/demos/python/sdk_wireless_camera_control/open_gopro/wifi/adapters/wireless.py +++ b/demos/python/sdk_wireless_camera_control/open_gopro/wifi/adapters/wireless.py @@ -299,10 +299,9 @@ def connect(self, ssid: str, password: str, timeout: float = 15) -> bool: discovered = False while not discovered and (time.time() - start) <= timeout: # Scan for network - response = cmd(f"{self.sudo} nmcli device wifi list") + response = cmd(f"{self.sudo} nmcli -f SSID device wifi list") for result in response.splitlines()[1:]: # Skip title row - # Remove * in IN-USE column since it makes the SSID column non-determinant - if result.strip(" *").split()[1] == ssid: + if result.strip() == ssid.strip(): discovered = True break if discovered: @@ -457,10 +456,9 @@ def connect(self, ssid: str, password: str, timeout: float = 15) -> bool: while not discovered and (time.time() - start) <= timeout: # Scan for network cmd(f"{self.sudo} nmcli device wifi rescan") - response = cmd(f"{self.sudo} nmcli device wifi list") + response = cmd(f"{self.sudo} nmcli -f SSID device wifi list") for result in response.splitlines()[1:]: # Skip title row - # Remove * in IN-USE column since it makes the SSID column non-determinant - if result.strip(" *").split()[1] == ssid: + if result.strip() == ssid.strip(): discovered = True break if discovered: @@ -693,8 +691,12 @@ def connect(self, ssid: str, password: str, timeout: float = 15) -> bool: response = cmd( r"/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport --scan" ) - for result in response.splitlines()[1:]: # Skip title row - if result.split()[0] == ssid: + lines = response.splitlines() + ssid_end_index = lines[0].index("SSID") + 4 # Find where the SSID column ends + + for result in lines[1:]: # Skip title row + current_ssid = result[:ssid_end_index].strip() + if current_ssid == ssid.strip(): discovered = True break if discovered: