ci wifi_tools: Log the wpa_supplicant interface state when trying to connect
Trigger reconnection if wpa_supplicant seems to have dropped the connection.
This commit is contained in:
parent
5cc9ef901e
commit
113721f8fc
1 changed files with 16 additions and 0 deletions
|
@ -51,6 +51,7 @@ class wpa_cli:
|
|||
iface_path = service.GetInterface(self.iface_name)
|
||||
self.iface_obj = bus.get_object("fi.w1.wpa_supplicant1", iface_path)
|
||||
self.iface_ifc = dbus.Interface(self.iface_obj, "fi.w1.wpa_supplicant1.Interface")
|
||||
self.iface_props = dbus.Interface(self.iface_obj, 'org.freedesktop.DBus.Properties')
|
||||
if self.iface_ifc is None:
|
||||
raise RuntimeError('supplicant : Failed to fetch interface')
|
||||
|
||||
|
@ -61,6 +62,14 @@ class wpa_cli:
|
|||
else:
|
||||
self.connected = True
|
||||
|
||||
def _get_iface_property(self, name):
|
||||
""" Read the property with 'name' from the wi-fi interface object
|
||||
|
||||
Note: The result is a dbus wrapped type, so should usually convert it to the corresponding native
|
||||
Python type
|
||||
"""
|
||||
return self.iface_props.Get("fi.w1.wpa_supplicant1.Interface", name)
|
||||
|
||||
def connect(self, ssid, password):
|
||||
if self.connected is True:
|
||||
self.iface_ifc.Disconnect()
|
||||
|
@ -76,7 +85,14 @@ class wpa_cli:
|
|||
retry = 10
|
||||
while retry > 0:
|
||||
time.sleep(5)
|
||||
|
||||
state = str(self._get_iface_property("State"))
|
||||
print("wpa iface state %s (scanning %s)" % (state, bool(self._get_iface_property("Scanning"))))
|
||||
if state in ["disconnected", "inactive"]:
|
||||
self.iface_ifc.Reconnect()
|
||||
|
||||
ip = get_wiface_IPv4(self.iface_name)
|
||||
print("wpa iface %s IP %s" % (self.iface_name, ip))
|
||||
if ip is not None:
|
||||
self.connected = True
|
||||
return ip
|
||||
|
|
Loading…
Reference in a new issue