Skip to content

Commit

Permalink
Kick wpa_supplicant periodically
Browse files Browse the repository at this point in the history
  • Loading branch information
davesteele committed Mar 24, 2019
1 parent 5c9aefa commit f5b2686
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions comitup/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import time

from comitup import iwscan
from comitup import wpa

from gi.repository.GLib import MainLoop, timeout_add
if __name__ == '__main__':
Expand Down Expand Up @@ -147,6 +148,8 @@ def hotspot_timeout():
else:
log.info('AP active - skipping CONNECTING scan')

wpa.check_wpa(modemgr.get_ap_device().Interface)


#
# Connecting state
Expand Down Expand Up @@ -230,6 +233,9 @@ def connected_timeout():
log.warning("Connection lost on timeout")
set_state('HOTSPOT')

if modemgr.get_mode() == modemgr.MULTI_MODE:
wpa.check_wpa(modemgr.get_ap_device().Interface)


#
# State Management
Expand Down
42 changes: 42 additions & 0 deletions comitup/wpa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/python3
# Copyright (c) 2019 David Steele <[email protected]>
#
# SPDX-License-Identifier: GPL-2.0-or-later
# License-Filename: LICENSE

import logging
import subprocess
import time

log = logging.getLogger("comitup")

# The AP hotspot is eventually failing. Restarting wpa_supplicant recovers it.
# I haven't found a way to detect that the wpa_supplicant is not working
# properly without involving the outside world.
#
# The minimal workaround fix is to call disconnect, then reconnect from
# wpa_cli.

last_kick_time = 0
kick_period_secs = 5*60


def needs_kick(devstring):
return (time.time() - kick_period_secs) > last_kick_time


def kick_wpa(devstring):
global last_kick_time

log.debug("Kicking wpa on {}".format(devstring))

for wpa_cmd in ("disconnect", "reconnect"):
shell_cmd = "/sbin/wpa_cli -i {0} {1}".format(devstring, wpa_cmd)
subprocess.run(shell_cmd.split())

last_kick_time = time.time()


def check_wpa(devstring):
if needs_kick(devstring):
kick_wpa(devstring)

0 comments on commit f5b2686

Please sign in to comment.