@@ -51,6 +51,7 @@ def __init__(self, iface, reset_on_exit=False):
51
51
iface_path = service .GetInterface (self .iface_name )
52
52
self .iface_obj = bus .get_object ("fi.w1.wpa_supplicant1" , iface_path )
53
53
self .iface_ifc = dbus .Interface (self .iface_obj , "fi.w1.wpa_supplicant1.Interface" )
54
+ self .iface_props = dbus .Interface (self .iface_obj , 'org.freedesktop.DBus.Properties' )
54
55
if self .iface_ifc is None :
55
56
raise RuntimeError ('supplicant : Failed to fetch interface' )
56
57
@@ -61,6 +62,14 @@ def __init__(self, iface, reset_on_exit=False):
61
62
else :
62
63
self .connected = True
63
64
65
+ def _get_iface_property (self , name ):
66
+ """ Read the property with 'name' from the wi-fi interface object
67
+
68
+ Note: The result is a dbus wrapped type, so should usually convert it to the corresponding native
69
+ Python type
70
+ """
71
+ return self .iface_props .Get ("fi.w1.wpa_supplicant1.Interface" , name )
72
+
64
73
def connect (self , ssid , password ):
65
74
if self .connected is True :
66
75
self .iface_ifc .Disconnect ()
@@ -76,7 +85,13 @@ def connect(self, ssid, password):
76
85
ip = None
77
86
retry = 10
78
87
while retry > 0 :
88
+ time .sleep (5 )
89
+ state = str (self ._get_iface_property ("State" ))
90
+ print ("wpa iface state %s (scanning %s)" % (state , bool (self ._get_iface_property ("Scanning" ))))
91
+ if state in ["disconnected" , "inactive" ]:
92
+ self .iface_ifc .Reconnect ()
79
93
ip = get_wiface_IPv4 (self .iface_name )
94
+ print ("wpa iface %s IP %s" % (self .iface_name , ip ))
80
95
if ip is not None :
81
96
self .connected = True
82
97
return ip
0 commit comments