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

Function background_arp_scan_loop

webapp_modern.py:14824–14902  ·  view source on GitHub ↗

Continuously run ARP scans to keep network data fresh

()

Source from the content-addressed store, hash-verified

14822 try:
14823 wifi_manager = getattr(shared_data, 'ragnar_instance', None)
14824 if not wifi_manager or not hasattr(wifi_manager, 'wifi_manager'):
14825 return jsonify({'error': 'Wi-Fi manager not available'}), 503
14826
14827 wm = wifi_manager.wifi_manager
14828
14829 # Stop AP mode if active
14830 if wm.ap_mode_active:
14831 logger.info("Force recovery: Stopping AP mode")
14832 wm.stop_ap_mode()
14833 time.sleep(2) # Give time for AP to shut down properly
14834
14835 # Force a WiFi search
14836 logger.info("Force recovery: Starting aggressive WiFi search")
14837 wm.wifi_validation_failures = 0
14838 wm.consecutive_validation_cycles_failed = 0
14839
14840 # Try to connect in a separate thread to avoid blocking
14841 def attempt_reconnect():
14842 success = wm._endless_loop_wifi_search()
14843 if success:
14844 logger.info("Force recovery: Successfully reconnected to WiFi")
14845 else:
14846 logger.warning("Force recovery: Failed to reconnect to WiFi")
14847
14848 recovery_thread = threading.Thread(target=attempt_reconnect, daemon=True)
14849 recovery_thread.start()
14850
14851 return jsonify({
14852 'success': True,
14853 'message': 'WiFi recovery initiated - searching for known networks...'
14854 })
14855
14856 except Exception as e:
14857 logger.error(f"Error forcing WiFi recovery: {e}")
14858 return jsonify({'error': str(e)}), 500
14859
14860@app.route('/api/wifi/log')
14861def get_wifi_log():
14862 """Get comprehensive WiFi logs including system status, Ragnar WiFi manager, and e-paper display updates"""
14863 try:
14864 wifi_log_data = {
14865 'timestamp': datetime.now().isoformat(),
14866 'system_wifi': {},
14867 'ragnar_wifi_manager': {},
14868 'epaper_display': {}
14869 }
14870
14871 # === SYSTEM WIFI STATUS ===
14872 try:
14873 wifi_log_data['system_wifi'] = {}
14874
14875 # Get SSID
14876 try:
14877 result = subprocess.run(['iwgetid', '-r'], capture_output=True, text=True, timeout=3)
14878 wifi_log_data['system_wifi']['ssid'] = result.stdout.strip() if result.returncode == 0 else None
14879 wifi_log_data['system_wifi']['connected'] = result.returncode == 0 and result.stdout.strip()
14880 except Exception as e:
14881 wifi_log_data['system_wifi']['ssid_error'] = str(e)

Callers

nothing calls this directly

Calls 10

update_netkb_entryFunction · 0.85
update_wifi_network_dataFunction · 0.85
debugMethod · 0.80
errorMethod · 0.80
emitMethod · 0.80
criticalMethod · 0.80
startMethod · 0.45
sleepMethod · 0.45
itemsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected