Skip to content

Commit 828f454

Browse files
author
guoping.liu
committed
update ipv4 for zero manager
1 parent 1d8161f commit 828f454

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

supervisor/supervisor.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -475,15 +475,8 @@ def onNetworkDisconnect(self):
475475

476476
def onNetworkConnected(self):
477477
logger.info("## Supervisor: Network onNetworkConnected() ...")
478-
try:
479-
logger.info(f"Attempting to restart Zeroconf with IP: {self.wifi_status.ip_address}")
480-
success = self.zeroconf_manager.start(self.wifi_status.ip_address)
481-
if success:
482-
logger.info("Zeroconf restarted successfully")
483-
else:
484-
logger.warning("Zeroconf restart returned False")
485-
except Exception as e:
486-
logger.error(f"Failed to (re)start Zeroconf on connect: {e}", exc_info=True)
478+
# Use update_ip method which handles retry logic internally
479+
self.zeroconf_manager.update_ip(self.wifi_status.ip_address)
487480

488481
def update_wifi_info(self, ip_address, ssid):
489482
"""Update WiFi information cache"""

supervisor/zero_manager.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,33 @@ def update_ip(self, ip_address: Optional[str]) -> None:
141141
Handle IP changes:
142142
- valid new IP: re-register on the new IP
143143
- invalid/empty IP: stop advertising
144+
- empty IP: retry with delay
144145
"""
145146
with self._lock:
146147
if ip_address and self._is_valid_ipv4(ip_address):
147148
if ip_address != self._ip:
148149
self.start(ip_address)
150+
elif not ip_address or ip_address == "":
151+
# IP is empty, retry after a short delay
152+
logger.debug(f"IP address is empty, scheduling retry in 2 seconds")
153+
threading.Timer(2.0, self._retry_with_current_ip).start()
149154
else:
150155
self.stop()
151156
self._ip = None
152157

158+
def _retry_with_current_ip(self) -> None:
159+
"""Retry getting IP address and starting Zeroconf"""
160+
try:
161+
from .utils.wifi_utils import get_wlan0_ip
162+
current_ip = get_wlan0_ip()
163+
if current_ip and self._is_valid_ipv4(current_ip):
164+
logger.info(f"Retry: Got IP address {current_ip}, starting Zeroconf")
165+
self.start(current_ip)
166+
else:
167+
logger.warning(f"Retry: Still no valid IP address (got: {current_ip})")
168+
except Exception as e:
169+
logger.error(f"Retry failed: {e}")
170+
153171
def _get_wlan0_mac(self) -> str:
154172
"""Get MAC address of wlan0 interface (last 8 characters, uppercase)."""
155173
try:

0 commit comments

Comments
 (0)