-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
51 lines (38 loc) · 1.17 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python3
import sys
import socket
from argparse import ArgumentParser
import time
def send(text):
ip = "10.10.123.3"
port = 48899
byte_array = convert_to_bytes(text)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((ip, port))
s.send(byte_array)
s.close()
def convert_to_bytes(message):
encoded = ":".join("{:02x}".format(ord(c)) for c in message)
encoded = encoded.split(':')
values = ['0x' + s for s in encoded]
values = [int(v,16) for v in values]
values.append(13)
return bytearray(values)
def Main(args):
parser = ArgumentParser()
parser.add_argument("-ssid", help="your Wi-Fi SSID; i.e. -ssid MyWifi", required=True)
parser.add_argument("-pswd", help="your Wi-Fi Password; i.e. -pass MyPassword", required=True)
args = parser.parse_args()
send("AT+WSSSID="+args.ssid)
print("WiFi Set")
time.sleep(0.5)
send("AT+WSKEY=WPA2PSK,AES,"+args.pswd)
print("Password Set")
time.sleep(0.5)
send("AT+WMODE=STA")
print("Switching to station mode")
time.sleep(0.5)
send("AT+Z")
print("Disconnected")
if __name__ == '__main__':
Main(sys.argv)