wifi debug

This commit is contained in:
IrvingGao 2024-05-27 21:57:07 +08:00
parent 9aba50be67
commit da770aafeb
1 changed files with 23 additions and 11 deletions

View File

@ -19,6 +19,20 @@ except ImportError:
# blue: APP # blue: APP
# red: hotspot # red: hotspot
def network_error_light():
error_time = datetime.datetime.now()
while led_enabled:
orangepi.set_led_off('blue')
orangepi.set_led_on('red')
time.sleep(0.5)
orangepi.set_led_on('blue')
orangepi.set_led_off('red')
time.sleep(0.5)
if error_time + datetime.timedelta(seconds=5) < datetime.datetime.now():
break
close_app()
app = Flask(__name__) app = Flask(__name__)
def close_app(): def close_app():
@ -67,11 +81,19 @@ def check_wifi_connection():
for line in lines: for line in lines:
columns = line.split() columns = line.split()
print(columns) print(columns)
'''
['wlan0', 'wifi', 'disconnected', '--']
['p2p-dev-wlan0', 'wifi-p2p', 'disconnected', '--']
['eth0', 'ethernet', 'unavailable', '--']
['lo', 'loopback', 'unmanaged', '--']
'''
if len(columns) >= 4 and columns[2] == "connected": if len(columns) >= 4 and columns[2] == "connected":
wifi_ssid = columns[3] wifi_ssid = columns[3]
if led_enabled: if led_enabled:
orangepi.set_led_off('blue') orangepi.set_led_off('blue')
return True, wifi_ssid return True, wifi_ssid
elif len(columns) >= 4 and columns[0] == "wlan0" and columns[2] == "unmanaged":
network_error_light()
return False, None return False, None
def scan_wifi(): def scan_wifi():
@ -81,17 +103,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:
print(f"{datetime.datetime.now()}: Error scanning Wi-Fi: {e}") print(f"{datetime.datetime.now()}: Error scanning Wi-Fi: {e}")
error_time = datetime.datetime.now() network_error_light()
while led_enabled:
orangepi.set_led_off('blue')
orangepi.set_led_on('red')
time.sleep(0.5)
orangepi.set_led_on('blue')
orangepi.set_led_off('red')
time.sleep(0.5)
if error_time + datetime.timedelta(seconds=5) < datetime.datetime.now():
break
close_app()
ssid_list = [] ssid_list = []
wifi_list = [] wifi_list = []
output = result.stdout.strip() output = result.stdout.strip()