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

Method __init__

wifi_manager.py:30–137  ·  view source on GitHub ↗
(self, shared_data)

Source from the content-addressed store, hash-verified

28 """Manages Wi-Fi connections, AP mode, and configuration for Ragnar"""
29
30 def __init__(self, shared_data):
31 self.shared_data = shared_data
32 self.logger = Logger(name="WiFiManager", level=logging.INFO)
33
34 # Initialize database for WiFi caching and analytics
35 try:
36 self.db = get_db(currentdir=shared_data.currentdir)
37 self.logger.info("WiFi database manager initialized")
38 except Exception as e:
39 self.logger.error(f"Failed to initialize WiFi database: {e}")
40 self.db = None
41
42 # Setup dedicated AP mode logging
43 self.setup_ap_logger()
44
45 # WiFi analytics tracking
46 self.current_connection_id = None # Track current connection for duration logging
47
48 # State management
49 self.wifi_connected = False
50 self.ap_mode_active = False
51 self.connection_attempts = 0
52 self.last_connection_attempt = None
53 self.connection_check_interval = 10 # Check every 10 seconds for responsive monitoring
54 self.connection_timeout = shared_data.config.get('wifi_initial_connection_timeout', 120) # 2 minutes initial wait
55 self.max_connection_attempts = 3
56
57 # Endless Loop Timing Configuration
58 self.endless_loop_active = False
59 self.endless_loop_start_time = None
60 self.boot_completed_time = None
61 self.wifi_search_timeout = 120 # 2 minutes to search for WiFi
62 self.ap_mode_timeout = 180 # 3 minutes in AP mode
63 self.wifi_validation_interval = 180 # 3 minutes between WiFi validations
64 self.wifi_validation_retries = 5 # 5 validation attempts (changed from 3)
65 self.wifi_validation_retry_interval = 10 # 10 seconds between validation retries
66 # While parked in AP mode, how often to look for a known network again.
67 # Tracked as "seconds since the last check" rather than by testing the
68 # uptime against a multiple — the monitoring loop ticks on a ~10s sleep
69 # plus however long the checks took, so it never lands on exact seconds.
70 self.ap_reconnect_check_interval = 30
71 self.last_ap_reconnect_check = 0.0
72 # Settling time before an unattended box starts looking for its network
73 # again. Short, because "unattended" is the whole precondition — the
74 # case that needs protecting is a client connected to the AP, and that
75 # is handled by its own check rather than by waiting out a clock.
76 self.ap_recovery_grace = 30
77 # Set by _check_known_networks_available: how many networks we could
78 # rejoin at all, and when a non-disruptive scan last actually returned
79 # results. Together they decide whether dropping the AP to hunt for a
80 # network could ever pay off — see _handle_ap_mode_monitoring.
81 self.known_networks_count = 0
82 self.last_successful_scan = 0.0
83 # How stale the last working scan must be before we stop trusting the
84 # non-disruptive path and fall back to tearing the AP down to search.
85 self.scan_trust_window = 300
86 self.last_wifi_validation = None
87 self.wifi_validation_failures = 0

Callers

nothing calls this directly

Calls 8

setup_ap_loggerMethod · 0.95
load_wifi_configMethod · 0.95
LoggerClass · 0.90
get_dbFunction · 0.90
detect_wifi_interfaceFunction · 0.90
infoMethod · 0.80
errorMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected