From 113721f8fc075789e1721ccc255d29e18dae9fe5 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 25 Jun 2020 18:18:04 +1000 Subject: [PATCH] ci wifi_tools: Log the wpa_supplicant interface state when trying to connect Trigger reconnection if wpa_supplicant seems to have dropped the connection. --- tools/ci/python_packages/wifi_tools.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/ci/python_packages/wifi_tools.py b/tools/ci/python_packages/wifi_tools.py index 13376e52e..bc3a7aab8 100644 --- a/tools/ci/python_packages/wifi_tools.py +++ b/tools/ci/python_packages/wifi_tools.py @@ -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