From 9949c7f58c0bc9b750360d9b2c3efcd614af0549 Mon Sep 17 00:00:00 2001 From: IrvingGao <1729854488@qq.com> Date: Sun, 9 Jun 2024 15:06:31 +0800 Subject: [PATCH] [wifi] update --- wifi_manager.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/wifi_manager.py b/wifi_manager.py index 571019a..c440390 100644 --- a/wifi_manager.py +++ b/wifi_manager.py @@ -49,7 +49,7 @@ def edit_line_in_file(file_path, search_string, replacement_string): else: file.write(line) - print("The line has been edited.") + print(f"{datetime.datetime.now()}: The line has been edited.") except FileNotFoundError: print(f"The file {file_path} does not exist.") except IOError as e: @@ -66,6 +66,7 @@ def save_local_ip(): # save local_ip to file with open('local_ip.txt', 'w') as f: f.write(local_ip) + print(f"{datetime.datetime.now()}: Local IP address: {local_ip}") return local_ip except Exception as e: print(f"Error getting private IP: {e}") @@ -116,7 +117,7 @@ def close_hotspot(): def check_wifi_connection(): cmd = "nmcli dev status" result = subprocess.run(cmd, shell=True, capture_output=True, text=True) - time.sleep(1) + time.sleep(2) output = result.stdout.strip() lines = output.split("\n")[1:] # Skip the header line for line in lines: @@ -150,7 +151,7 @@ def check_wifi_connection(): network_error_light() subprocess.Popen('sudo systemctl restart NetworkManager', shell=True) # subprocess.run(['sudo', 'systemctl', 'restart', 'NetworkManager'], check=True) - time.sleep(5) + time.sleep(2) return False, None def scan_wifi(): @@ -161,6 +162,7 @@ def scan_wifi(): except subprocess.CalledProcessError as e: print(f"{datetime.datetime.now()}: Error scanning Wi-Fi: {e}") network_error_light() + print(f"{datetime.datetime.now()}: Wi-Fi scan complete...") ssid_list = [] wifi_list = [] output = result.stdout.strip() @@ -207,6 +209,8 @@ def scan_wifi(): # print("强度:", strength) 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: break @@ -304,7 +308,7 @@ def submit(): wifi_list = scan_wifi() start_hotspot() else: - save_wifi(wifi_ssid, password) # 保存连接成功的Wi-Fi信息 + save_wifi(ssid, password) # 保存连接成功的Wi-Fi信息 return redirect(url_for('index'))