Skip to content

Commit d5f200e

Browse files
committed
Fix issue with WiFi on but not connected
1 parent 9696527 commit d5f200e

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

scripts/wifi

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ def get_wifi_info():
4646
info['agrctlrssi'] = re.sub('[^0-9-]','', remove_all(' RSSI : ', line).strip())
4747
elif " Noise : " in line:
4848
info['agrctlnoise'] = re.sub('[^0-9-]','', remove_all(' Noise : ', line).strip())
49-
49+
5050
elif " Tx Rate : " in line:
5151
info['lasttxrate'] = re.sub('[^0-9]','', remove_all(' Tx Rate : ', line.split(".")[0]).strip())
5252
elif " MCS Index : " in line:
5353
info['mcs'] = re.sub('[^0-9]','', remove_all(' MCS Index : ', line).strip())
5454

5555
elif " Power : On" in line:
56-
info['state'] = "running"
56+
if 'state' in info and info['state'] != "init":
57+
info['state'] = "running"
58+
5759
elif " Op Mode : " in line:
5860
info['op_mode'] = remove_all(' Op Mode : ', line.replace('STA', 'station')).strip()
5961

@@ -63,11 +65,14 @@ def get_wifi_info():
6365
info['phy_mode'] = "802." + remove_all(' PHY Mode : ', line).strip()
6466
elif " Country Code : " in line:
6567
info['country_code'] = remove_all(' Country Code : ', line).strip()
66-
elif " BSSID : " in line:
67-
info['bssic'] = format_mac_address(remove_all(' BSSID : ', line).strip())
68+
69+
elif " BSSID : " in line and "None" not in line:
70+
info['bssid'] = format_mac_address(remove_all(' BSSID : ', line).strip())
71+
elif " BSSID : " in line and "None" in line:
72+
info['state'] = "init" # Show that the wifi is on, but not connected
6873
elif " SSID : " in line:
6974
info['ssid'] = remove_all(' SSID : ', line).strip()
70-
75+
7176
elif " Guard Interval : " in line:
7277
info['guardinterval'] = remove_all(' Guard Interval : ', line).strip()
7378
elif " NSS : " in line:
@@ -265,9 +270,9 @@ def get_networks():
265270
channel_history["timestamp"] = string_to_time(channel[channel_entry])
266271
# Get historical channel by comparing last connected with channel's timestamp
267272
if "JoinedBySystemAt" in plist[network] and channel[channel_entry] == plist[network]["JoinedBySystemAt"]:
268-
ssid_entry["channel"] = channel["Channel"]
273+
ssid_entry["channel"] = channel["Channel"]
269274
elif "JoinedByUserAt" in plist[network] and channel[channel_entry] == plist[network]["JoinedByUserAt"]:
270-
ssid_entry["channel"] = channel["Channel"]
275+
ssid_entry["channel"] = channel["Channel"]
271276
history.append(channel_history)
272277
ssid_entry["channel_history"] = history
273278
except Exception:
@@ -292,7 +297,7 @@ def get_networks():
292297
networks_json.append(ssid_entry)
293298

294299
return {"known_networks":json.dumps(networks_json)}
295-
300+
296301
except Exception:
297302
return {"known_networks":""}
298303

@@ -398,7 +403,7 @@ def get_networks_legacy():
398403
channel_history["timestamp"] = string_to_time(channel_entry.split(' =')[1].replace('";', "").replace(';', "").replace(' "', "").strip())
399404
# Get historical channel by comparing last connected with channel's timestamp
400405
if network_entry.count(channel_entry.split(' =')[1].replace('";', "").replace(';', "").replace(' "', "").strip()) == 2:
401-
ssid_entry["channel"] = channel_history["channel"]
406+
ssid_entry["channel"] = channel_history["channel"]
402407
history.append(channel_history)
403408
ssid_entry["channel_history"] = history[:-1]
404409
except Exception:
@@ -422,12 +427,12 @@ def get_networks_legacy():
422427

423428
networks_json.append(ssid_entry)
424429
return {"known_networks":json.dumps(networks_json)}
425-
430+
426431
except Exception:
427432
return {"known_networks":""}
428433

429434
def string_to_time(date_time):
430-
435+
431436
if (date_time == "0" or date_time == 0):
432437
return ""
433438
else:
@@ -488,7 +493,7 @@ def main():
488493

489494
# Only merge in the known networks if not empty
490495
if known_networks != {}:
491-
result = merge_two_dicts(known_networks, result)
496+
result = merge_two_dicts(known_networks, result)
492497
else:
493498
result = merge_two_dicts(get_wifi_info(), known_networks)
494499

0 commit comments

Comments
 (0)