[wifi] short wait time

This commit is contained in:
IrvingGao 2024-06-13 14:03:32 +08:00
parent a64b22c329
commit 3e88c60997
1 changed files with 5 additions and 5 deletions

View File

@ -128,7 +128,7 @@ def close_hotspot():
def check_wifi_connection(): def check_wifi_connection():
cmd = "nmcli dev status" cmd = "nmcli dev status"
result = subprocess.run(cmd, shell=True, capture_output=True, text=True) result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
time.sleep(2) time.sleep(0.5)
output = result.stdout.strip() output = result.stdout.strip()
lines = output.split("\n")[1:] # Skip the header line lines = output.split("\n")[1:] # Skip the header line
for line in lines: for line in lines:
@ -162,7 +162,7 @@ def check_wifi_connection():
network_error_light_1() network_error_light_1()
subprocess.Popen('sudo systemctl restart NetworkManager', shell=True) subprocess.Popen('sudo systemctl restart NetworkManager', shell=True)
# subprocess.run(['sudo', 'systemctl', 'restart', 'NetworkManager'], check=True) # subprocess.run(['sudo', 'systemctl', 'restart', 'NetworkManager'], check=True)
time.sleep(1) time.sleep(0.5)
return check_wifi_connection() return check_wifi_connection()
return False, None return False, None
@ -249,7 +249,7 @@ def connect_wifi(ssid, password):
def disconnect_wifi(): def disconnect_wifi():
try: try:
output = subprocess.check_output(['nmcli', 'dev', 'disconnect', 'iface', 'wlan0']) output = subprocess.check_output(['nmcli', 'dev', 'disconnect', 'iface', 'wlan0'])
time.sleep(1) time.sleep(0.5)
output_str = output.decode('utf-8') # 将输出转换为字符串 output_str = output.decode('utf-8') # 将输出转换为字符串
if "successfully disconnected" in output_str: if "successfully disconnected" in output_str:
print(f"{datetime.datetime.now()}: Wi-Fi disconnected successfully") print(f"{datetime.datetime.now()}: Wi-Fi disconnected successfully")
@ -308,9 +308,9 @@ def submit():
# 关闭热点 # 关闭热点
close_hotspot() close_hotspot()
time.sleep(1) time.sleep(0.5)
scan_wifi() scan_wifi()
time.sleep(1) time.sleep(0.5)
# 连接到用户选择的 Wi-Fi 网络 # 连接到用户选择的 Wi-Fi 网络
if connect_wifi(ssid, password): if connect_wifi(ssid, password):