in deepracer_systems_pkg/deepracer_systems_pkg/network_monitor_module/wifi_config_utils.py [0:0]
def get_available_wifi_networks():
"""Returns available WiFi networks as a list sorted by signal strength.
Returns:
list: List of available WiFi networks.
"""
try:
cmd = ["nmcli",
"-terse",
"-colors", "no",
"-fields", "ssid,signal",
"-escape", "no",
"device", "wifi"]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if (p.returncode != 0) or (err != ""):
raise Exception(err)
network_dict = dict()
for line in out.splitlines():
try:
network, signal = line.split(":", 1)
if (network not in network_dict) or (int(signal) > network_dict[network]):
network_dict[network] = int(signal)
except Exception as ex:
pass
return sorted(network_dict.items(), key=operator.itemgetter(1), reverse=True)
except Exception as ex:
print(f"Failed to retrieve available WiFi networds: {ex}")
return list()