Handle initial Wi-Fi connection with endless loop behavior
(self)
| 682 | self.logger.warning( |
| 683 | f"WiFi interface(s) disappeared (unplugged?): {disappeared}" |
| 684 | ) |
| 685 | if not self.wifi_connected and not self.ap_mode_active: |
| 686 | self.logger.info( |
| 687 | "USB antenna removed while disconnected — triggering WiFi reconnect" |
| 688 | ) |
| 689 | threading.Thread( |
| 690 | target=self._endless_loop_wifi_search, |
| 691 | daemon=True, |
| 692 | name="wifi-reconnect-usb-unplug", |
| 693 | ).start() |
| 694 | prev_ifaces = current_ifaces |
| 695 | except Exception as e: |
| 696 | self.logger.debug(f"USB interface monitor error: {e}") |
| 697 | |
| 698 | # ============================================================================ |
| 699 | # WARDRIVING / WEB PORTAL COORDINATION |
| 700 | # ============================================================================ |
| 701 | |
| 702 | def _is_wardriving_active(self): |
| 703 | """Return True if the wardriving engine is currently running.""" |
| 704 | try: |
| 705 | ragnar = getattr(self.shared_data, 'ragnar_instance', None) |
| 706 | if ragnar and hasattr(ragnar, '_wd_engine'): |
| 707 | return getattr(ragnar._wd_engine, '_running', False) |
| 708 | import webapp_modern |
| 709 | engine = getattr(webapp_modern, '_wardriving_engine', None) |
| 710 | if engine: |
| 711 | return getattr(engine, '_running', False) |
| 712 | except Exception: |
| 713 | pass |
| 714 | return self.shared_data.config.get('wardriving_on_boot', False) |
| 715 | |
| 716 | def _sync_web_portal_for_wardriving(self): |
| 717 | """Stop web portal when wardriving with no WiFi; restart when WiFi returns. |
| 718 | |
| 719 | Called every monitoring iteration so the portal state converges quickly |
| 720 | regardless of how wardriving was started (boot flag, API call, etc.). |
| 721 | """ |
| 722 | if not self._is_wardriving_active(): |
| 723 | return |
| 724 | ragnar = getattr(self.shared_data, 'ragnar_instance', None) |
| 725 | if not ragnar: |
| 726 | return |
no test coverage detected