1234567891011121314151617181920212223242526272829 |
- import sys
- import time
- import serial
- from serial.tools import list_ports
- if len(sys.argv) != 5:
- print("usage: config.py <SSID> <Password> <Host> <Port>")
- exit(1)
- _, *config = sys.argv
- for p in list_ports.comports():
- try:
- ser = serial.Serial(p.device, 38400)
- for i in range(5):
- time.sleep(3)
- data = str(ser.read(ser.inWaiting()), "ASCII")
- print(data)
- ser.write(bytes("CONFIG:{},{},{},{}\r\n".format(*config) + 'A'*51, "ASCII"))
- for k in range(20):
- time.sleep(1)
- data = str(ser.read(ser.inWaiting()), "ASCII")
- print(data)
- if data.find(config[0]) > -1:
- print('success')
- exit(0)
- ser.write(bytes('A'*5100, "ASCII"))
- except serial.SerialException as e:
- print(e)
|