-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_esp8266uart.py
executable file
·104 lines (86 loc) · 2.46 KB
/
test_esp8266uart.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import esp8266uart
esp = esp8266uart.ESP8266(1, 115200)
print('Testing generic methods')
print('=======================')
print('AT startup...')
if esp.test():
print('Success!')
else:
print('Failed!')
#print('Soft-Reset...')
#if esp.reset():
# print('Success!')
#else:
# print('Failed!')
print('Another AT startup...')
if esp.test():
print('Success!')
else:
print('Failed!')
print()
print('Testing WIFI methods')
print('====================')
wifi_mode = 1
print("Testing get_mode/set_mode of value '%s'(%i)..." % (esp8266uart.WIFI_MODES[wifi_mode], wifi_mode))
esp.set_mode(wifi_mode)
if esp.get_mode() == wifi_mode:
print('Success!')
else:
print('Failed!')
print('Disconnecting from WLAN...')
if esp.disconnect():
print('Success!')
else:
print('Failed!')
print('Disconnecting from WLAN again...')
if esp.disconnect():
print('Success!')
else:
print('Failed!')
print('Checking if not connected WLAN...')
if esp.get_accesspoint() == None:
print('Success!')
else:
print('Failed!')
print('Scanning for WLANs...')
wlans = esp.list_all_accesspoints()
for wlan in wlans:
print(wlan)
print("Scanning for WLAN '%s'..." % (wlan['ssid']))
for wlan2 in esp.list_accesspoints(wlan['ssid']):
print(wlan2)
print('Setting access point mode...')
if esp.set_mode(esp8266uart.WIFI_MODES['Access Point + Station']):
print('Failed!')
else:
print('Success!')
print('Reading access point configuration')
print(esp.get_accesspoint_config())
print('Listing all stations connected to the module in access point mode...')
print(esp.list_stations())
print('Checking DHCP client and server settings...')
for mode in range(3):
print(esp.set_dhcp_config(mode, 0))
print(esp.set_dhcp_config(mode, 1))
print(esp.set_dhcp_config(mode, True))
print(esp.set_dhcp_config(mode, False))
try:
print(esp.set_dhcp_config(0, 2))
except esp8266uart.CommandError:
print('Obvious error caught!')
try:
print(esp.set_dhcp_config(4, 1))
except esp8266uart.CommandError:
print('Obvious error caught!')
print('Setting autoconnect to access point in station mode...')
esp.set_autoconnect(True)
esp.set_autoconnect(False)
esp.set_autoconnect(True)
print('Reading and setting the station IP...')
print(esp.get_station_ip())
esp.set_station_ip('192.168.1.10')
print(esp.get_station_ip())
print('Reading and setting the access point IP...')
print(esp.get_accesspoint_ip())
esp.set_accesspoint_ip('192.168.1.1')
print(esp.get_accesspoint_ip())