Skip to content

Commit

Permalink
Example script for setup of E5576-320
Browse files Browse the repository at this point in the history
  • Loading branch information
timvlaer committed Jul 16, 2024
1 parent d9efc50 commit 47be794
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
69 changes: 69 additions & 0 deletions examples/initial_setup_e5576-320.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from argparse import ArgumentParser

from huawei_lte_api.Client import Client
from huawei_lte_api.Connection import Connection
from time import sleep

parser = ArgumentParser()
parser.add_argument('--password', type=str)
parser.add_argument('--new-password', type=str)
parser.add_argument('--ssid', type=str)
parser.add_argument('--wpa-password', type=str)
args = parser.parse_args()

original_password = args["password"]
new_password = args["new-password"]

wifi_ssid = args["ssid"]
wifi_password = args["wpa-password"]

url = 'http://192.168.8.1/'
with Connection(url, password=original_password) as connection:
client = Client(connection)

locale = "en-us"
print("Set language to " + locale)
print(client.language.set_current_language(locale))

print("Accept privacy policy")
print(client.app.accept_privacypolicy(approve=True))

print("Set autoupdate config")
print(client.online_update.set_autoupdate_config(autoupdate=True))

print("Set basic information")
print(client.device.set_basic_information())

print(f"Set wlan ({wifi_ssid}/{wifi_password}) and account settings (admin/{new_password})")
resp = client.wlan.set_wlan_guide_settings(
ssid=wifi_ssid, wpa_psk=wifi_password, current_password=original_password, new_password=new_password
)
print(resp)

print("Admin password changed, reconnect...")
sleep(10)
failing = True
while failing:
try:
with Connection(url, password=new_password) as connection:
print("Get basic information")
status = client.monitoring.status()
if status["ConnectionStatus"] == "901":
failing = False
else:
sleep(60)
except Exception as e:
print("Failed with exception: " + str(e) + ", sleeping 60s")
sleep(60)

with Connection(url, password=new_password) as connection:
client = Client(connection)

print("Set basic information")
print(client.device.set_basic_information())

# restart wifi to see effect of the new ssid
# see toggle_wifi.py



6 changes: 3 additions & 3 deletions huawei_lte_api/Session.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def post_get(self,
refresh_csrf: bool = False,
prefix: str = 'api',
is_encrypted: bool = False,
is_json: bool = False
is_json: bool = False,
) -> GetResponseType:
return cast(
GetResponseType,
Expand All @@ -213,7 +213,7 @@ def post_set(self,
refresh_csrf: bool = False,
prefix: str = 'api',
is_encrypted: bool = False,
is_json: bool = False
is_json: bool = False,
) -> SetResponseType:
return cast(
SetResponseType,
Expand All @@ -227,7 +227,7 @@ def _post(self,
refresh_csrf: bool = False,
prefix: str = 'api',
is_encrypted: bool = False,
is_json: bool = False
is_json: bool = False,
) -> Union[GetResponseType, SetResponseType]:

headers = {}
Expand Down

0 comments on commit 47be794

Please sign in to comment.