Skip to content

Commit

Permalink
Update wifi handling to properly detected all states
Browse files Browse the repository at this point in the history
Now correctly detects if wifi is connected, disconnected or actually disabled
  • Loading branch information
d-rez committed Oct 30, 2017
1 parent 2b4bf31 commit c707f1b
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
}
icon_battery_critical_shutdown = iconpath2 + "alert-outline-red.png"

statefile_wifi ="/sys/class/net/wlan0/carrier"
wifi_carrier = "/sys/class/net/wlan0/carrier" # 1 when wifi connected, 0 when disconnected and/or ifdown
wifi_linkmode = "/sys/class/net/wlan0/link_mode" # 1 when ifup, 0 when ifdown
bt_devices_dir="/sys/class/bluetooth"
env_cmd="vcgencmd get_throttled"

Expand Down Expand Up @@ -108,13 +109,21 @@ def wifi():

new_wifi_state = InterfaceState.DISABLED
try:
resfile=open(statefile_wifi, "r")
state=int(resfile.read().rstrip())
resfile.close()
if state == 1:
f = open(wifi_carrier, "r")
carrier_state = int(f.read().rstrip())
f.close()
if carrier_state == 1:
# ifup and connected to AP
new_wifi_state = InterfaceState.CONNECTED
elif state == 0:
new_wifi_state = InterfaceState.ENABLED
elif carrier_state == 0:
f = open(wifi_linkmode, "r")
linkmode_state = int(f.read().rstrip())
f.close()
if linkmode_state == 1:
# ifup but not connected to any network
new_wifi_state = InterfaceState.ENABLED
# else - must be ifdown

except IOError:
pass

Expand Down

0 comments on commit c707f1b

Please sign in to comment.