1212class WiFi (Activity ):
1313
1414 prefs = None
15- access_points = {}
15+ saved_access_points = {}
1616 last_tried_ssid = ""
1717 last_tried_result = ""
1818 have_network = True
@@ -24,7 +24,7 @@ class WiFi(Activity):
2424 scan_button_scan_text = "Rescan"
2525 scan_button_scanning_text = "Scanning..."
2626
27- ssids = []
27+ scanned_ssids = []
2828 busy_scanning = False
2929 busy_connecting = False
3030 error_timer = None
@@ -69,9 +69,9 @@ def onResume(self, screen):
6969 if not self .prefs :
7070 self .prefs = mpos .config .SharedPreferences ("com.micropythonos.system.wifiservice" )
7171
72- self .access_points = self .prefs .get_dict ("access_points" )
73- print (f"loaded access points from preferences: { self .access_points } " )
74- if len (self .ssids ) == 0 :
72+ self .saved_access_points = self .prefs .get_dict ("access_points" )
73+ print (f"loaded access points from preferences: { self .saved_access_points } " )
74+ if len (self .scanned_ssids ) == 0 :
7575 if WifiService .wifi_busy == False :
7676 WifiService .wifi_busy = True
7777 self .start_scan_networks ()
@@ -99,11 +99,11 @@ def scan_networks_thread(self):
9999 try :
100100 if self .have_network :
101101 networks = wlan .scan ()
102- self .ssids = list (set (n [0 ].decode () for n in networks ))
102+ self .scanned_ssids = list (set (n [0 ].decode () for n in networks ))
103103 else :
104104 time .sleep (1 )
105- self .ssids = ["Home WiFi" , "Pretty Fly for a Wi Fi" , "Winternet is coming" , "The Promised LAN" ]
106- print (f"scan_networks: Found networks: { self .ssids } " )
105+ self .scanned_ssids = ["Home WiFi" , "Pretty Fly for a Wi Fi" , "Winternet is coming" , "The Promised LAN" ]
106+ print (f"scan_networks: Found networks: { self .scanned_ssids } " )
107107 except Exception as e :
108108 print (f"scan_networks: Scan failed: { e } " )
109109 self .show_error ("Wi-Fi scan failed" )
@@ -128,8 +128,7 @@ def refresh_list(self):
128128 print ("refresh_list: Clearing current list" )
129129 self .aplist .clean () # this causes an issue with lost taps if an ssid is clicked that has been removed
130130 print ("refresh_list: Populating list with scanned networks" )
131- self .ssids = list (set (self .ssids + list (ssid for ssid in self .access_points )))
132- for ssid in set (self .ssids ):
131+ for ssid in set (self .scanned_ssids + list (ssid for ssid in self .saved_access_points )):
133132 if len (ssid ) < 1 or len (ssid ) > 32 :
134133 print (f"Skipping too short or long SSID: { ssid } " )
135134 continue
@@ -144,7 +143,7 @@ def refresh_list(self):
144143 if status != "connected" :
145144 if self .last_tried_ssid == ssid : # implies not connected because not wlan.isconnected()
146145 status = self .last_tried_result
147- elif ssid in self .access_points :
146+ elif ssid in self .saved_access_points :
148147 status = "saved"
149148 label = lv .label (button )
150149 label .set_text (status )
@@ -177,9 +176,8 @@ def edit_network_result_callback(self, result):
177176 forget = data .get ("forget" )
178177 if forget :
179178 try :
180- del self .access_points [ssid ]
181- self .ssids .remove (ssid )
182- editor .put_dict ("access_points" , self .access_points )
179+ del self .saved_access_points [ssid ]
180+ editor .put_dict ("access_points" , self .saved_access_points )
183181 editor .commit ()
184182 self .refresh_list ()
185183 except Exception as e :
@@ -188,9 +186,9 @@ def edit_network_result_callback(self, result):
188186 password = data .get ("password" )
189187 hidden = data .get ("hidden" )
190188 self .setPassword (ssid , password , hidden )
191- editor .put_dict ("access_points" , self .access_points )
189+ editor .put_dict ("access_points" , self .saved_access_points )
192190 editor .commit ()
193- print (f"access points: { self .access_points } " )
191+ print (f"access points: { self .saved_access_points } " )
194192 self .start_attempt_connecting (ssid , password )
195193
196194 def start_attempt_connecting (self , ssid , password ):
@@ -239,20 +237,20 @@ def attempt_connecting_thread(self, ssid, password):
239237 self .update_ui_threadsafe_if_foreground (self .refresh_list )
240238
241239 def findSavedPassword (self , ssid ):
242- ap = self .access_points .get (ssid )
240+ ap = self .saved_access_points .get (ssid )
243241 if ap :
244242 return ap .get ("password" )
245243 return None
246244
247245 def setPassword (self , ssid , password , hidden = False ):
248- ap = self .access_points .get (ssid )
246+ ap = self .saved_access_points .get (ssid )
249247 if ap :
250248 ap ["password" ] = password
251249 if hidden is True :
252250 ap ["hidden" ] = True
253251 return
254252 # if not found, then add it:
255- self .access_points [ssid ] = { "password" : password , "hidden" : hidden }
253+ self .saved_access_points [ssid ] = { "password" : password , "hidden" : hidden }
256254
257255
258256class EditNetwork (Activity ):
0 commit comments