MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / _parse_iwlist_output

Method _parse_iwlist_output

wifi_manager.py:1757–1807  ·  view source on GitHub ↗

Parse iwlist scan output into network list for Pi Zero W2 compatibility

(self, output)

Source from the content-addressed store, hash-verified

1755 subprocess.run(
1756 ['nmcli', 'dev', 'wifi', 'rescan', 'ifname', secondary],
1757 capture_output=True, text=True, timeout=15
1758 )
1759 # Short pause to let the radio collect results
1760 time.sleep(2)
1761
1762 result = subprocess.run(
1763 ['nmcli', '-t', '-f', 'SSID,SIGNAL,SECURITY', 'dev', 'wifi', 'list', 'ifname', secondary],
1764 capture_output=True, text=True, timeout=15
1765 )
1766
1767 if result.returncode != 0:
1768 self.ap_logger.warning(
1769 f"nmcli scan on secondary {secondary} failed (rc={result.returncode}): {result.stderr}"
1770 )
1771 # Fall back to iwlist on the secondary adapter
1772 return self._run_iwlist_scan(
1773 secondary,
1774 system_profiles=system_profiles,
1775 known_ssids=known_set,
1776 log_target=self.ap_logger
1777 )
1778
1779 networks = []
1780 for line in result.stdout.strip().split('\n'):
1781 if not line:
1782 continue
1783 parts = self._parse_nmcli_terse_line(line)
1784 if len(parts) >= 2 and parts[0]:
1785 ssid = parts[0]
1786 security = parts[2] if len(parts) > 2 and parts[2] else 'Open'
1787 is_known = ssid in known_set or ssid in system_profiles
1788 networks.append({
1789 'ssid': ssid,
1790 'signal': int(parts[1]) if parts[1].isdigit() else 0,
1791 'security': security,
1792 'known': is_known,
1793 'has_system_profile': ssid in system_profiles,
1794 'scan_method': 'secondary_nmcli'
1795 })
1796
1797 # Deduplicate and sort by signal
1798 seen = set()
1799 unique = []
1800 for net in sorted(networks, key=lambda x: x['signal'], reverse=True):
1801 if net['ssid'] not in seen:
1802 seen.add(net['ssid'])
1803 unique.append(net)
1804
1805 if unique:
1806 self.ap_logger.info(f"Secondary adapter {secondary} found {len(unique)} networks (live scan)")
1807 return unique
1808
1809 except Exception as exc:
1810 self.ap_logger.warning(f"Secondary adapter scan failed on {secondary}: {exc}")

Callers 1

_run_iwlist_scanMethod · 0.95

Calls 4

appendMethod · 0.80
debugMethod · 0.80
errorMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected