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,23 @@ 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 access point. Must be less than 32 chars.
50+ :param str password: the password for the access point. Must be 8-63 chars.
51+ :param str enterprise_ident: the ident to use when connecting to an enterprise access point.
52+ :param str enterprise_user: the username to use when connecting to an enterprise access
53+ point.
4754 :param status_pixel: (Optional) The pixel device - A NeoPixel, DotStar,
4855 or RGB LED (default=None). The status LED, if given, turns red when
4956 attempting to connect to a Wi-Fi network or create an access point,
@@ -57,8 +64,8 @@ def __init__(
5764 # Read the settings
5865 self .esp = esp
5966 self .debug = debug
60- self .ssid = secrets [ " ssid" ]
61- self .password = secrets . get ( " password" , None )
67+ self .ssid = ssid
68+ self .password = password
6269 self .attempts = attempts
6370 self ._connection_type = connection_type
6471 self .statuspix = status_pixel
@@ -70,11 +77,11 @@ def __init__(
7077 ssl_context = adafruit_connection_manager .get_radio_ssl_context (self .esp )
7178 self ._requests = adafruit_requests .Session (pool , ssl_context )
7279
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" )
80+ # Check for WPA2 Enterprise values
81+ self .ent_ssid = ssid
82+ self .ent_ident = enterprise_ident
83+ self .ent_user = enterprise_user
84+ self .ent_password = password
7885
7986 # pylint: enable=too-many-arguments
8087
@@ -97,9 +104,9 @@ def connect(self):
97104 print ("MAC addr:" , [hex (i ) for i in self .esp .MAC_address ])
98105 for access_pt in self .esp .scan_networks ():
99106 print ("\t %s\t \t RSSI: %d" % (access_pt .ssid , access_pt .rssi ))
100- if self ._connection_type == ESPSPI_WiFiManager .NORMAL :
107+ if self ._connection_type == WiFiManager .NORMAL :
101108 self .connect_normal ()
102- elif self ._connection_type == ESPSPI_WiFiManager .ENTERPRISE :
109+ elif self ._connection_type == WiFiManager .ENTERPRISE :
103110 self .connect_enterprise ()
104111 else :
105112 raise TypeError ("Invalid WiFi connection type specified" )
@@ -347,3 +354,53 @@ def signal_strength(self):
347354 if not self .esp .is_connected :
348355 self .connect ()
349356 return self .esp .ap_info .rssi
357+
358+
359+ # pylint: disable=too-many-instance-attributes
360+ class ESPSPI_WiFiManager (WiFiManager ):
361+ """
362+ A legacy class to help manage the Wifi connection. Please update to using WiFiManager
363+ """
364+
365+ # pylint: disable=too-many-arguments
366+ def __init__ (
367+ self ,
368+ esp ,
369+ secrets ,
370+ status_pixel = None ,
371+ attempts = 2 ,
372+ connection_type = WiFiManager .NORMAL ,
373+ debug = False ,
374+ ):
375+ """
376+ :param ESP_SPIcontrol esp: The ESP object we are using
377+ :param dict secrets: The WiFi secrets dict
378+ The use of secrets.py to populate the secrets dict is deprecated
379+ in favor of using settings.toml.
380+ :param status_pixel: (Optional) The pixel device - A NeoPixel, DotStar,
381+ or RGB LED (default=None). The status LED, if given, turns red when
382+ attempting to connect to a Wi-Fi network or create an access point,
383+ turning green upon success. Additionally, if given, it will turn blue
384+ when attempting an HTTP method or returning IP address, turning off
385+ upon success.
386+ :type status_pixel: NeoPixel, DotStar, or RGB LED
387+ :param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=2)
388+ :param const connection_type: (Optional) Type of WiFi connection: NORMAL or ENTERPRISE
389+ """
390+
391+ warnings .warn (
392+ "ESP32WiFiManager, which uses `secrets`, is deprecated. Use WifiManager instead and "
393+ "fetch values from settings.toml with `os.getenv()`."
394+ )
395+
396+ super ().__init__ (
397+ esp = esp ,
398+ ssid = secrets .get ("ssid" ),
399+ password = secrets .get ("password" ),
400+ enterprise_ident = secrets .get ("ent_ident" , "" ),
401+ enterprise_user = secrets .get ("ent_user" ),
402+ status_pixel = status_pixel ,
403+ attempts = attempts ,
404+ connection_type = connection_type ,
405+ debug = debug ,
406+ )
0 commit comments