1313
1414# pylint: disable=no-name-in-module
1515
16+ import warnings
1617from time import sleep
1718from micropython import const
1819import adafruit_connection_manager
2122
2223
2324# pylint: disable=too-many-instance-attributes
24- class ESPSPI_WiFiManager :
25+ class WiFiManager :
2526 """
2627 A class to help manage the Wifi connection
2728 """
@@ -33,17 +34,22 @@ class ESPSPI_WiFiManager:
3334 def __init__ (
3435 self ,
3536 esp ,
36- secrets ,
37+ ssid ,
38+ password = None ,
39+ * ,
40+ enterprise_ident = None ,
41+ enterprise_user = None ,
3742 status_pixel = None ,
3843 attempts = 2 ,
3944 connection_type = NORMAL ,
4045 debug = False ,
4146 ):
4247 """
4348 :param ESP_SPIcontrol esp: The ESP object we are using
44- :param dict secrets: The WiFi and Adafruit IO secrets dict (See examples)
45- The use of secrets.py to populate the secrets dict is depreciated
46- in favor of using settings.toml.
49+ :param str ssid: the SSID of the created Access Point. Must be less than 32 chars.
50+ :param str password: the password of the created Access Point. Must be 8-63 chars.
51+ :param str enterprise_ident: the ident when connecting to an enterprise Access Point.
52+ :param str enterprise_user: the user when connecting to an enterprise Access Point.
4753 :param status_pixel: (Optional) The pixel device - A NeoPixel, DotStar,
4854 or RGB LED (default=None). The status LED, if given, turns red when
4955 attempting to connect to a Wi-Fi network or create an access point,
@@ -57,8 +63,8 @@ def __init__(
5763 # Read the settings
5864 self .esp = esp
5965 self .debug = debug
60- self .ssid = secrets [ " ssid" ]
61- self .password = secrets . get ( " password" , None )
66+ self .ssid = ssid
67+ self .password = password
6268 self .attempts = attempts
6369 self ._connection_type = connection_type
6470 self .statuspix = status_pixel
@@ -70,11 +76,11 @@ def __init__(
7076 ssl_context = adafruit_connection_manager .get_radio_ssl_context (self .esp )
7177 self ._requests = adafruit_requests .Session (pool , ssl_context )
7278
73- # Check for WPA2 Enterprise keys in the secrets dictionary and load them if they exist
74- self .ent_ssid = secrets . get ( "ent_ssid" , secrets [ " ssid" ])
75- self .ent_ident = secrets . get ( "ent_ident" , "" )
76- self .ent_user = secrets . get ( "ent_user" )
77- self .ent_password = secrets . get ( "ent_password" )
79+ # Check for WPA2 Enterprise values
80+ self .ent_ssid = ssid
81+ self .ent_ident = enterprise_ident
82+ self .ent_user = enterprise_user
83+ self .ent_password = password
7884
7985 # pylint: enable=too-many-arguments
8086
@@ -97,9 +103,9 @@ def connect(self):
97103 print ("MAC addr:" , [hex (i ) for i in self .esp .MAC_address ])
98104 for access_pt in self .esp .scan_networks ():
99105 print ("\t %s\t \t RSSI: %d" % (access_pt .ssid , access_pt .rssi ))
100- if self ._connection_type == ESPSPI_WiFiManager .NORMAL :
106+ if self ._connection_type == WiFiManager .NORMAL :
101107 self .connect_normal ()
102- elif self ._connection_type == ESPSPI_WiFiManager .ENTERPRISE :
108+ elif self ._connection_type == WiFiManager .ENTERPRISE :
103109 self .connect_enterprise ()
104110 else :
105111 raise TypeError ("Invalid WiFi connection type specified" )
@@ -347,3 +353,60 @@ def signal_strength(self):
347353 if not self .esp .is_connected :
348354 self .connect ()
349355 return self .esp .ap_info .rssi
356+
357+
358+ # pylint: disable=too-many-instance-attributes
359+ class ESPSPI_WiFiManager (WiFiManager ):
360+ """
361+ A legacy class to help manage the Wifi connection. Please update to using WiFiManager
362+ """
363+
364+ NORMAL = const (1 )
365+ ENTERPRISE = const (2 )
366+
367+ # pylint: disable=too-many-arguments
368+ def __init__ (
369+ self ,
370+ esp ,
371+ secrets ,
372+ status_pixel = None ,
373+ attempts = 2 ,
374+ connection_type = NORMAL ,
375+ debug = False ,
376+ ):
377+ """
378+ :param ESP_SPIcontrol esp: The ESP object we are using
379+ :param dict secrets: The WiFi secrets dict
380+ The use of secrets.py to populate the secrets dict is depreciated
381+ in favor of using settings.toml.
382+ :param status_pixel: (Optional) The pixel device - A NeoPixel, DotStar,
383+ or RGB LED (default=None). The status LED, if given, turns red when
384+ attempting to connect to a Wi-Fi network or create an access point,
385+ turning green upon success. Additionally, if given, it will turn blue
386+ when attempting an HTTP method or returning IP address, turning off
387+ upon success.
388+ :type status_pixel: NeoPixel, DotStar, or RGB LED
389+ :param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=2)
390+ :param const connection_type: (Optional) Type of WiFi connection: NORMAL or ENTERPRISE
391+ """
392+
393+ warnings .warn (
394+ "ESP32WiFiManager, which uses `secrets`, is deprecated. Use WifiManager instead and "
395+ "fetch values from settings.toml with `os.getenv()`."
396+ )
397+
398+ ssid = secrets .get ("ssid" )
399+ password = secrets .get ("secrets" , None )
400+ enterprise_ident = secrets .get ("ent_ident" , "" )
401+ enterprise_user = secrets .get ("ent_user" )
402+ super ().__init__ (
403+ esp = esp ,
404+ ssid = ssid ,
405+ password = password ,
406+ enterprise_ident = enterprise_ident ,
407+ enterprise_user = enterprise_user ,
408+ status_pixel = status_pixel ,
409+ attempts = attempts ,
410+ connection_type = connection_type ,
411+ debug = debug ,
412+ )
0 commit comments