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

Method check_network_connectivity

wifi_manager.py:1261–1295  ·  view source on GitHub ↗

Check for any usable network link, preferring Ethernet when present.

(self)

Source from the content-addressed store, hash-verified

1259 # Get both Ragnar's known networks AND system profiles
1260 ragnar_known = [net['ssid'] for net in self.known_networks]
1261 system_profiles = self.get_system_wifi_profiles()
1262 all_known = list(set(ragnar_known + system_profiles)) # Combine and deduplicate
1263
1264 # Recorded so AP monitoring can tell "nothing to rejoin" apart from
1265 # "something to rejoin, just not in range right now".
1266 self.known_networks_count = len(all_known)
1267 if not all_known:
1268 return False
1269
1270 # Strategy 1: Use secondary adapter for a reliable nmcli scan
1271 secondary = self._find_secondary_wifi_interface()
1272 if secondary:
1273 try:
1274 subprocess.run(
1275 ['nmcli', 'dev', 'wifi', 'rescan', 'ifname', secondary],
1276 capture_output=True, text=True, timeout=15
1277 )
1278 time.sleep(1)
1279 result = subprocess.run(
1280 ['nmcli', '-t', '-f', 'SSID', 'dev', 'wifi', 'list', 'ifname', secondary],
1281 capture_output=True, text=True, timeout=15
1282 )
1283 if result.returncode == 0:
1284 available_ssids = [
1285 line.strip() for line in result.stdout.strip().split('\n')
1286 if line.strip()
1287 ]
1288 # Any result at all proves the scan path works here, so
1289 # "found nothing" can be trusted as genuinely nothing.
1290 if available_ssids:
1291 self.last_successful_scan = time.time()
1292 for known_ssid in all_known:
1293 if known_ssid in available_ssids:
1294 self.logger.info(f"Known network '{known_ssid}' detected via secondary adapter {secondary}")
1295 return True
1296 except Exception as e:
1297 self.logger.debug(f"Secondary adapter scan failed during known-network check: {e}")
1298

Callers 4

get_statusMethod · 0.95
start_orchestratorMethod · 0.80

Calls 5

check_wifi_connectionMethod · 0.95
debugMethod · 0.80
errorMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected