ESP32/reconfig_simple.py

56 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python3
import serial
import time
import glob
SSID = "ClubHouse2G"
PASSWORD = "ez2remember"
START_IP = 51
devices = sorted(glob.glob('/dev/ttyUSB*'))
num_devices = len(devices)
ok_devices = 0
print(f"Found {num_devices} devices\n")
for idx, dev in enumerate(devices):
ip = f"192.168.1.{START_IP + idx}"
print(f"[{idx}] Configuring {dev}{ip}")
try:
ser = serial.Serial(dev, 115200, timeout=1)
time.sleep(0.5) # Let serial port stabilize
# Send configuration
ser.write(b"CFG\n")
time.sleep(0.1)
ser.write(f"SSID:{SSID}\n".encode())
time.sleep(0.1)
ser.write(f"PASS:{PASSWORD}\n".encode())
time.sleep(0.1)
ser.write(f"IP:{ip}\n".encode())
time.sleep(0.1)
ser.write(b"MASK:255.255.255.0\n")
time.sleep(0.1)
ser.write(b"GW:192.168.1.1\n")
time.sleep(0.1)
ser.write(b"DHCP:0\n")
time.sleep(0.1)
ser.write(b"END\n")
# Wait for OK response
time.sleep(0.5)
response = ser.read(100).decode('utf-8', errors='ignore')
if 'OK' in response:
print(f" ✓ Got OK response")
ok_devices += 1
ser.close()
except Exception as e:
print(f" ✗ Error: {e}")
time.sleep(0.5)
print(f"\nOk={ok_devices} Not ok={num_devices - ok_devices}")
print("\nWaiting 30s for connections...")
time.sleep(30)
print(f"Done! Test with: NUM_DEVICES={num_devices} ./test_devices.sh")