Main endless loop monitoring thread
(self)
| 829 | self.logger.error(f"Error enabling WiFi: {e}") |
| 830 | |
| 831 | # Wait up to 60 seconds for automatic connection (check every 5 seconds) |
| 832 | timeout = 60 # 1 minute to connect |
| 833 | check_interval = 5 |
| 834 | elapsed = 0 |
| 835 | |
| 836 | while elapsed < timeout and not self.should_exit: |
| 837 | time.sleep(check_interval) |
| 838 | elapsed += check_interval |
| 839 | |
| 840 | if self.check_wifi_connection(): |
| 841 | self.wifi_connected = True |
| 842 | self.shared_data.wifi_connected = True |
| 843 | self._set_current_ssid(self.get_current_ssid()) |
| 844 | self.logger.info(f"Endless Loop: Successfully auto-connected to {self.current_ssid} after {elapsed}s") |
| 845 | self._save_connection_state(self.current_ssid, True) |
| 846 | self.last_wifi_validation = time.time() |
| 847 | self.consecutive_validation_cycles_failed = 0 |
| 848 | self.no_connection_cycles = 0 # Reset failsafe counter on success |
| 849 | self._trigger_initial_ping_sweep(self.current_ssid) |
| 850 | return True |
| 851 | else: |
| 852 | self.logger.debug(f"Endless Loop: Waiting for auto-connection... ({elapsed}s/{timeout}s)") |
| 853 | |
| 854 | # Strengthened validation before AP fallback: perform a strong connectivity check (ping 8.8.8.8) |
| 855 | self.logger.info("Endless Loop: Performing strong connectivity verification before AP fallback") |
| 856 | if self._strong_wifi_presence_check(): |
| 857 | self.logger.info("Endless Loop: Strong check indicates WiFi connectivity; aborting AP fallback") |
| 858 | self.wifi_connected = True |
| 859 | self.shared_data.wifi_connected = True |
| 860 | self._set_current_ssid(self.get_current_ssid()) |
| 861 | self._save_connection_state(self.current_ssid, True) |
| 862 | self.last_wifi_validation = time.time() |
| 863 | self.no_connection_cycles = 0 |
| 864 | self._trigger_initial_ping_sweep(self.current_ssid) |
| 865 | return True |
| 866 | |
| 867 | # No WiFi connected after 1 minute, switch to AP mode |
| 868 | self.logger.info(f"Endless Loop: No auto-connection established after {timeout}s, switching to AP mode") |
| 869 | self._endless_loop_start_ap_mode() |
| 870 | return False |
| 871 | |
| 872 | def _endless_loop_start_ap_mode(self): |
| 873 | """Start AP mode as part of endless loop. |
| 874 | |
| 875 | Skipped for the two modes that own the radio themselves: |
| 876 | |
| 877 | - **Wardriving** needs wlan0 for scanning, and AP mode (hostapd) would |
| 878 | take over the interface. Wardriving has its own phone-access AP, |
| 879 | started deliberately with KEY1. |
| 880 | - **On-Screen Network Diagnostic Mode** is a field test of the network |
| 881 | the box is actually on. Silently converting the radio into an access |
| 882 | point mid-test invalidates every reading on the screen. |
| 883 | |
| 884 | WiFi search itself is NOT suppressed by either — the box should keep |
| 885 | trying to rejoin a known network. Only the AP fallback is skipped. |
| 886 | """ |
| 887 | if self.shared_data.config.get('wardriving_enabled', False): |
| 888 | self.logger.info("Endless Loop: AP mode skipped — wardriving is enabled") |
no test coverage detected