forked from chanakalin/hilinkapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiTest.py
138 lines (133 loc) · 5.85 KB
/
apiTest.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from HiLinkAPI import webui
import logging
from time import sleep, time
from datetime import datetime
logging.basicConfig(filename="hilinkapitest.log", format='%(asctime)s -- %(name)s::%(levelname)s -- {%(pathname)s:%(lineno)d} -- %(message)s', level=logging.DEBUG, datefmt="%Y-%m-%d %I:%M:%S %p:%Z")
try:
webUIArray = [
# webui("E3372h-153", "192.168.18.1", "admin", "admin", logger=logging),
webui("E3372h-320", "192.168.8.1", "admin", "abcd@1234", logger=logging),
# webui("E8372h-320", "192.168.10.1", "admin", "abcd@1234",logger=logging),
]
for webUI in webUIArray:
try:
# print known errors
# print("############# Known errors ############")
# knownErrors = webUI.getKnownErrors()
# for errorCode in knownErrors.keys():
# print(f"{errorCode} = {str(knownErrors[errorCode])}")
# print("########################################")
# start
webUI.start()
# wait until validate the session
while not webUI.getValidSession():
# check for active errors
if webUI.getActiveError() is not None:
error = webUI.getActiveError()
print(error)
sleep(5)
# check for login wait time
if webUI.getLoginWaitTime() > 0:
print(f"Login wait time available = {webUI.getLoginWaitTime()} minutes")
sleep(5)
########
# Enable data roaming and set max idle time out into 2 hours (7200 seconds)
webUI.configureDataConnection(True, 7200)
########
# query data connection
webUI.queryDataConnection()
# query device info
webUI.queryDeviceInfo()
# query WAN IP
webUI.queryWANIP()
# query network name
webUI.queryNetwork()
###################
#######Call gets###
print(f"devicename = {webUI.getDeviceName()}")
print(f"webui version = {webUI.getWebUIVersion()}")
print(f"login required = {webUI.getLoginRequired()}")
print(f"valid session = {webUI.validateSession()}")
print("########################################")
# session refresh interval
# webUI.setSessionRefreshInteval(10)
print(f"Session refresh interval = {webUI.getSessionRefreshInteval()}")
print("########################################")
# data connection info
print("########################################")
print(f"Data roaming = {webUI.getDataRoaming()}")
print(f"Max idle time = {webUI.getMaxIdleTime()}")
print("########################################")
# set primary and secondary network modes
netMode = webUI.setNetwokModes("LTE", "WCDMA")
print(f"Network mode setting = {netMode}")
print(webUI.getNetwokModes())
# Device info
print("########################################")
deviceInfo = webUI.getDeviceInfo()
for key in deviceInfo.keys():
if len(key) >= 8:
print(f"{key}\t:{deviceInfo[key]}")
else:
print(f"{key}\t\t:{deviceInfo[key]}")
#
print("########################################")
print(f"Network = {webUI.getNetwork()}")
print("########################################\n")
######### Reboot #########
# webUI.reboot()
#######Reboot end#########
# Connection on off
print(f"\t{datetime.now()}")
webUI.queryWANIP()
print(f"\tWAPN IP = {webUI.getWANIP()}")
print(f"\tSwitching - Connection off = {webUI.switchConnection(False)}")
sleep(1)
print(f"\tSwitching - Connection on = {webUI.switchConnection(True)}")
webUI.queryWANIP()
while webUI.getWANIP() is None:
webUI.queryWANIP()
print(f"\tWAPN IP = {webUI.getWANIP()}")
print("")
# switching LTE / WCDMA
times = 1
while times > 0:
times -= 1
rotation = open("rotation", 'a')
print(f"\t{datetime.now()}")
rotation.write(f"{datetime.now()}\n")
webUI.queryWANIP()
print(f"\tWAPN IP = {webUI.getWANIP()}")
rotation.write(f"WAPN IP = {webUI.getWANIP()}\n")
status = webUI.switchNetworMode(False)
print(f"\tSwitching - WCDMA = \t{status}")
rotation.write(f"Switching - WCDMA = \t{status}\n")
sleep(1)
status = webUI.switchNetworMode(True)
print(f"\tSwitching - LTE = \t{status}")
rotation.write(f"Switching - LTE = \t{status}\n")
webUI.queryWANIP()
while webUI.getWANIP() is None:
webUI.queryWANIP()
print(f"\tWAPN IP = {webUI.getWANIP()}")
rotation.write(f"WAPN IP = {webUI.getWANIP()}\n")
print(f"\t{datetime.now()}")
rotation.write(f"{datetime.now()}\n\n")
print("\n")
rotation.close()
sleep(60)
# webUI.switchDHCPIPBlock("192.168.8.1")
print("****************************************\n\n")
###################
# stop
webUI.stop()
while(not webUI.isStopped()):
webUI.stop()
print(f"Waiting for stop")
sleep(1)
except Exception as e:
print(e)
except Exception as e:
print(e)
# End of the test
print("\n")