53 lines
1.4 KiB
Python
Executable File
53 lines
1.4 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*'))
|
|
print(f"Found {len(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")
|
|
|
|
ser.close()
|
|
except Exception as e:
|
|
print(f" ✗ Error: {e}")
|
|
|
|
time.sleep(0.5)
|
|
|
|
print("\nWaiting 30s for connections...")
|
|
time.sleep(30)
|
|
print("Done! Test with: NUM_DEVICES=31 ./test_devices.sh")
|