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

Method check_wifi_connection

wifi_manager.py:1297–1343  ·  view source on GitHub ↗

Check if Wi-Fi is connected using multiple methods

(self)

Source from the content-addressed store, hash-verified

1295 return True
1296 except Exception as e:
1297 self.logger.debug(f"Secondary adapter scan failed during known-network check: {e}")
1298
1299 # Strategy 2: Try a quick scan using iwlist on AP interface (less disruptive)
1300 try:
1301 result = subprocess.run(['sudo', 'iwlist', self.ap_interface, 'scan'],
1302 capture_output=True, text=True, timeout=10)
1303 if result.returncode == 0:
1304 available_ssids = []
1305 for line in result.stdout.split('\n'):
1306 if 'ESSID:' in line:
1307 ssid = line.split('ESSID:')[1].strip('"')
1308 if ssid and ssid != '<hidden>':
1309 available_ssids.append(ssid)
1310
1311 if available_ssids:
1312 self.last_successful_scan = time.time()
1313
1314 # Check if any known networks (Ragnar or system) are available
1315 for known_ssid in all_known:
1316 if known_ssid in available_ssids:
1317 self.logger.info(f"Known network '{known_ssid}' detected while in AP mode")
1318 return True
1319 except Exception as e:
1320 self.logger.debug(f"iwlist scan failed: {e}")
1321
1322 return False
1323
1324 except Exception as e:
1325 self.logger.error(f"Error checking for known networks: {e}")
1326 return False
1327
1328 def exit_ap_mode_from_web(self):
1329 """Exit AP mode and start WiFi search (called from web interface)"""
1330 self.logger.info("Endless Loop: Exit AP mode requested from web interface")
1331 self.force_exit_ap_mode = True
1332 return True
1333
1334 def _is_fresh_boot(self):
1335 """Determine if this is a fresh system boot or just a service restart"""
1336 try:
1337 # First check if we were recently running (service restart)
1338 if self._was_recently_running():
1339 self.logger.info("WiFi manager was recently running - treating as service restart")
1340 return False
1341
1342 # Check system uptime
1343 with open('/proc/uptime', 'r') as f:
1344 uptime_seconds = float(f.read().split()[0])
1345
1346 # If system has been up for less than 5 minutes, consider it a fresh boot

Callers 12

stopMethod · 0.95
connect_to_networkMethod · 0.95
get_statusMethod · 0.95
is_wifi_connectedMethod · 0.80
start_orchestratorMethod · 0.80
is_wifi_connectedMethod · 0.80

Calls 3

errorMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected