Stop Access Point mode
(self)
| 2378 | if int(ap_running_time) % 60 == 0: # Log every minute |
| 2379 | self.ap_logger.info(f"AP running for {ap_running_time:.0f}s, clients: {self.ap_clients_count}, connected: {self.ap_clients_connected}") |
| 2380 | |
| 2381 | return False |
| 2382 | |
| 2383 | def get_autoconnect_networks(self): |
| 2384 | """Get networks that are set to autoconnect in NetworkManager""" |
| 2385 | try: |
| 2386 | result = subprocess.run(['nmcli', '-t', '-f', 'NAME,TYPE,AUTOCONNECT', 'connection', 'show'], |
| 2387 | capture_output=True, text=True, timeout=10) |
| 2388 | if result.returncode == 0: |
| 2389 | autoconnect_networks = [] |
| 2390 | for line in result.stdout.strip().split('\n'): |
| 2391 | if line and '802-11-wireless' in line and 'yes' in line: |
| 2392 | parts = line.split(':') |
| 2393 | if len(parts) >= 3: |
| 2394 | network_name = parts[0] |
| 2395 | autoconnect_networks.append(network_name) |
| 2396 | |
| 2397 | self.logger.info(f"Found {len(autoconnect_networks)} autoconnect networks: {autoconnect_networks}") |
| 2398 | return autoconnect_networks |
| 2399 | |
| 2400 | return [] |
| 2401 | |
| 2402 | except Exception as e: |
| 2403 | self.logger.warning(f"Error getting autoconnect networks: {e}") |
| 2404 | return [] |
| 2405 | |
| 2406 | def try_autoconnect_networks(self): |
| 2407 | """Try to connect to any available autoconnect networks""" |
| 2408 | autoconnect_networks = self.get_autoconnect_networks() |
| 2409 | |
| 2410 | if not autoconnect_networks: |
| 2411 | self.logger.info("No autoconnect networks available") |
| 2412 | return False |
| 2413 | |
| 2414 | # Scan for available networks |
| 2415 | available_networks = self.scan_networks() |
| 2416 | available_ssids = [net['ssid'] for net in available_networks] |
| 2417 | |
| 2418 | # Try to connect to any autoconnect network that's available |
| 2419 | for network in autoconnect_networks: |
| 2420 | if network in available_ssids: |
| 2421 | self.logger.info(f"Attempting to connect to autoconnect network: {network}") |
| 2422 | try: |
| 2423 | # Use nmcli to bring up the connection |
| 2424 | result = subprocess.run(['nmcli', 'connection', 'up', network], |
| 2425 | capture_output=True, text=True, timeout=30) |
no test coverage detected