improved ip addr detection
This commit is contained in:
parent
1288eabd10
commit
24d64ac9e7
|
|
@ -50,8 +50,9 @@ class DeployWorker:
|
||||||
|
|
||||||
# Regex Patterns
|
# Regex Patterns
|
||||||
self.regex_ready = re.compile(r'Initialization complete|GPS synced|No WiFi config found', re.IGNORECASE)
|
self.regex_ready = re.compile(r'Initialization complete|GPS synced|No WiFi config found', re.IGNORECASE)
|
||||||
self.regex_got_ip = re.compile(r'got ip:(\d+\.\d+\.\d+\.\d+)', re.IGNORECASE)
|
# Match output from 'mode_status' command
|
||||||
self.regex_error = re.compile(r'Error:|Failed|Disconnect|Auth Expire', re.IGNORECASE)
|
self.regex_status_connected = re.compile(r'WiFi connected: Yes', re.IGNORECASE)
|
||||||
|
self.regex_status_ip = re.compile(r'Got IP: (\d+\.\d+\.\d+\.\d+)', re.IGNORECASE)
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
try:
|
try:
|
||||||
|
|
@ -118,9 +119,9 @@ class DeployWorker:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# A. Boot Wait
|
||||||
self.log.info("Waiting for boot...")
|
self.log.info("Waiting for boot...")
|
||||||
booted = False
|
booted = False
|
||||||
# Increased boot timeout slightly
|
|
||||||
end_time = time.time() + 10
|
end_time = time.time() + 10
|
||||||
while time.time() < end_time:
|
while time.time() < end_time:
|
||||||
try:
|
try:
|
||||||
|
|
@ -133,8 +134,9 @@ class DeployWorker:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not booted:
|
if not booted:
|
||||||
self.log.warning("Boot prompt missed, sending config blind...")
|
self.log.warning("Boot prompt missed, attempting config anyway...")
|
||||||
|
|
||||||
|
# B. Send Config
|
||||||
self.log.info(f"Sending config for {self.target_ip}...")
|
self.log.info(f"Sending config for {self.target_ip}...")
|
||||||
config_str = (f"CFG\nSSID:{self.args.ssid}\nPASS:{self.args.password}\n"
|
config_str = (f"CFG\nSSID:{self.args.ssid}\nPASS:{self.args.password}\n"
|
||||||
f"IP:{self.target_ip}\nMASK:{self.args.netmask}\nGW:{self.args.gateway}\n"
|
f"IP:{self.target_ip}\nMASK:{self.args.netmask}\nGW:{self.args.gateway}\n"
|
||||||
|
|
@ -142,32 +144,48 @@ class DeployWorker:
|
||||||
writer.write(config_str.encode('utf-8'))
|
writer.write(config_str.encode('utf-8'))
|
||||||
await writer.drain()
|
await writer.drain()
|
||||||
|
|
||||||
self.log.info("Verifying IP (Timeout: 30s)...")
|
# C. Active Polling Verification
|
||||||
|
self.log.info("Verifying configuration (Polling)...")
|
||||||
start_verify = time.time()
|
start_verify = time.time()
|
||||||
|
|
||||||
# INCREASED TIMEOUT to 30s
|
|
||||||
while time.time() < start_verify + 30:
|
while time.time() < start_verify + 30:
|
||||||
|
# 1. Clear buffer
|
||||||
try:
|
try:
|
||||||
line_b = await asyncio.wait_for(reader.readline(), timeout=1.0)
|
while True:
|
||||||
|
await asyncio.wait_for(reader.read(1024), timeout=0.01)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# 2. Send status request
|
||||||
|
writer.write(b"\nmode_status\n")
|
||||||
|
await writer.drain()
|
||||||
|
|
||||||
|
# 3. Read response for ~2 seconds
|
||||||
|
poll_end = time.time() + 2.0
|
||||||
|
while time.time() < poll_end:
|
||||||
|
try:
|
||||||
|
line_b = await asyncio.wait_for(reader.readline(), timeout=0.5)
|
||||||
line = line_b.decode('utf-8', errors='ignore').strip()
|
line = line_b.decode('utf-8', errors='ignore').strip()
|
||||||
|
|
||||||
# Success Check
|
# Check for success indicators in status output
|
||||||
m = self.regex_got_ip.search(line)
|
if self.regex_status_connected.search(line):
|
||||||
|
self.log.info(f"{Colors.GREEN}SUCCESS: Connected{Colors.RESET}")
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Also catch passive "Got IP" logs if they appear
|
||||||
|
m = self.regex_status_ip.search(line)
|
||||||
if m:
|
if m:
|
||||||
if m.group(1) == self.target_ip:
|
if m.group(1) == self.target_ip:
|
||||||
self.log.info(f"{Colors.GREEN}SUCCESS: Configured & Connected{Colors.RESET}")
|
self.log.info(f"{Colors.GREEN}SUCCESS: IP Confirmed ({m.group(1)}){Colors.RESET}")
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
self.log.warning(f"IP Mismatch: Got {m.group(1)}, Wanted {self.target_ip}")
|
|
||||||
|
|
||||||
# Failure Check
|
|
||||||
if self.regex_error.search(line):
|
|
||||||
self.log.warning(f"Device Reported Error: {line}")
|
|
||||||
|
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
continue
|
break
|
||||||
|
|
||||||
self.log.error("Timeout: Config sent, but device did not connect.")
|
# Wait a bit before next poll
|
||||||
|
await asyncio.sleep(1.0)
|
||||||
|
|
||||||
|
self.log.error("Timeout: Device did not confirm connection.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -181,7 +199,7 @@ def parse_args():
|
||||||
parser = argparse.ArgumentParser(description='Async ESP32 Mass Deployment')
|
parser = argparse.ArgumentParser(description='Async ESP32 Mass Deployment')
|
||||||
parser.add_argument('-d', '--dir', default=os.getcwd(), help='Project dir')
|
parser.add_argument('-d', '--dir', default=os.getcwd(), help='Project dir')
|
||||||
parser.add_argument('-s', '--ssid', help='WiFi SSID')
|
parser.add_argument('-s', '--ssid', help='WiFi SSID')
|
||||||
parser.add_argument('-P', '--password', help='WiFi Password') # Standardized -P
|
parser.add_argument('-P', '--password', help='WiFi Password')
|
||||||
parser.add_argument('--start-ip', default='192.168.1.51', help='Start IP')
|
parser.add_argument('--start-ip', default='192.168.1.51', help='Start IP')
|
||||||
parser.add_argument('-b', '--baud', type=int, default=460800, help='Flash baud')
|
parser.add_argument('-b', '--baud', type=int, default=460800, help='Flash baud')
|
||||||
parser.add_argument('--erase', action='store_true', help='Full erase first')
|
parser.add_argument('--erase', action='store_true', help='Full erase first')
|
||||||
|
|
@ -225,7 +243,6 @@ async def run_deployment(args):
|
||||||
|
|
||||||
# 3. Deploy
|
# 3. Deploy
|
||||||
print(f"{Colors.YELLOW}[3/3] Deploying to {len(devices)} devices...{Colors.RESET}")
|
print(f"{Colors.YELLOW}[3/3] Deploying to {len(devices)} devices...{Colors.RESET}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
start_ip_obj = ipaddress.IPv4Address(args.start_ip)
|
start_ip_obj = ipaddress.IPv4Address(args.start_ip)
|
||||||
except:
|
except:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue