[wifi] fix big bugs
This commit is contained in:
parent
c0e8bdd6af
commit
3b8ae02e10
|
@ -152,7 +152,7 @@ def init_networkmanager_file():
|
||||||
# network_error_light_1()
|
# network_error_light_1()
|
||||||
logging.info(f"{datetime.datetime.now()}: Wi-Fi NetworkManager Error: restart NetworkManager.")
|
logging.info(f"{datetime.datetime.now()}: Wi-Fi NetworkManager Error: restart NetworkManager.")
|
||||||
subprocess.Popen('sudo systemctl restart NetworkManager', shell=True)
|
subprocess.Popen('sudo systemctl restart NetworkManager', shell=True)
|
||||||
time.sleep(3)
|
time.sleep(5) # 不得修改该时间,保留足够长时间给NetworkManager重启完成,并连接以往WiFi。
|
||||||
|
|
||||||
# 检测 Wi-Fi 连接状态
|
# 检测 Wi-Fi 连接状态
|
||||||
def check_wifi_connection():
|
def check_wifi_connection():
|
||||||
|
@ -183,7 +183,7 @@ def scan_wifi():
|
||||||
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
logging.info(f"{datetime.datetime.now()}: Error scanning Wi-Fi: {e}")
|
logging.info(f"{datetime.datetime.now()}: Error scanning Wi-Fi: {e}")
|
||||||
network_error_light_2()
|
network_error_light_1()
|
||||||
return []
|
return []
|
||||||
logging.info(f"{datetime.datetime.now()}: Wi-Fi scan complete...")
|
logging.info(f"{datetime.datetime.now()}: Wi-Fi scan complete...")
|
||||||
ssid_list = []
|
ssid_list = []
|
||||||
|
@ -232,10 +232,12 @@ def scan_wifi():
|
||||||
# logging.info("强度:", strength)
|
# logging.info("强度:", strength)
|
||||||
|
|
||||||
wifi_list.append({'ssid': ssid, 'signal': strength, 'mac': mac_address})
|
wifi_list.append({'ssid': ssid, 'signal': strength, 'mac': mac_address})
|
||||||
with open('scaned_wifi_list.json', 'w') as f:
|
|
||||||
json.dump(wifi_list, f)
|
|
||||||
if len(wifi_list) == 15:
|
if len(wifi_list) == 15:
|
||||||
break
|
break
|
||||||
|
with open('scaned_wifi_list.json', 'w') as f:
|
||||||
|
json.dump(wifi_list, f)
|
||||||
|
logging.info(f"{datetime.datetime.now()}: Wi-Fi scaned list: {wifi_list}")
|
||||||
|
|
||||||
|
|
||||||
return wifi_list
|
return wifi_list
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue