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

Method run

Ragnar.py:68–116  ·  view source on GitHub ↗

Main loop for Ragnar. Waits for Wi-Fi connection and starts Orchestrator.

(self)

Source from the content-addressed store, hash-verified

66 pass
67
68 def run(self):
69 """Main loop for Ragnar. Waits for Wi-Fi connection and starts Orchestrator."""
70 logger.info("=" * 70)
71 logger.info("RAGNAR MAIN THREAD STARTING")
72 logger.info("=" * 70)
73
74 # Start PiSugar button listener (if available)
75 if self.pisugar_listener:
76 self.pisugar_listener.start()
77
78 # If wardriving-on-boot is enabled, kick wardriving off BEFORE the WiFi
79 # manager starts. wifi_manager.start() blocks ~5s minimum (longer with
80 # no AP available), and wardriving doesn't need WiFi connectivity —
81 # it scans interfaces directly. Running it in a daemon thread also
82 # lets us parallelize the GPS spin-up with WiFi startup, so the
83 # e-paper sees `running == True` within ~1s of boot instead of 20+.
84 wardriving_boot = self.shared_data.config.get('wardriving_on_boot', False)
85 if wardriving_boot:
86 logger.info("Wardriving-on-boot enabled. Starting wardriving early, orchestrator will be suppressed.")
87 # Wardriving and On-Screen Network Diagnostic mode both hijack the
88 # e-Paper display and the HAT keys, and the diagnostic layer wins the
89 # render race (see display.py) — leaving Ragnar stuck on the netdiag
90 # field-test screen even though wardriving is scanning underneath.
91 # They are mutually exclusive, so if diagnostic mode was left on,
92 # turn it off before wardriving takes over the panel.
93 if self.shared_data.config.get('network_diagnostic_mode', False):
94 logger.info("Disabling On-Screen Network Diagnostic mode: wardriving-on-boot takes the display.")
95 self.shared_data.config['network_diagnostic_mode'] = False
96 try:
97 self.shared_data.save_config()
98 except Exception as e:
99 logger.warning(f"Could not persist network_diagnostic_mode off at boot: {e}")
100 self.shared_data.manual_mode = True
101 threading.Thread(
102 target=self._start_wardriving_on_boot,
103 daemon=True,
104 name="wardriving-on-boot",
105 ).start()
106
107 # Initialize Wi-Fi management system
108 logger.info("Starting Wi-Fi management system...")
109 self.wifi_manager.start()
110 logger.info("Wi-Fi management system started")
111
112 # Main loop to keep Ragnar running
113 logger.info("Entering main Ragnar loop...")
114
115 loop_count = 0
116 while not self.shared_data.should_exit:
117 loop_count += 1
118 if loop_count % 6 == 1: # Log every 60 seconds (6 iterations * 10 sec)
119 logger.info(f"Ragnar main loop iteration {loop_count}, manual_mode={self.shared_data.manual_mode}")

Callers 15

_nmap_sudo_availableMethod · 0.45
_cleanup_dead_zapMethod · 0.45
install_missing_toolsMethod · 0.45
_stop_serviceMethod · 0.45
gather_wifi_interfacesFunction · 0.45
_check_ethernet_carrierFunction · 0.45

Calls 6

rangeFunction · 0.85
infoMethod · 0.80
startMethod · 0.45
getMethod · 0.45
sleepMethod · 0.45

Tested by 4

track_device_movementMethod · 0.36
dos_attackMethod · 0.36