13
13
14
14
# pylint: disable=no-name-in-module
15
15
16
+ import warnings
16
17
from time import sleep
17
18
from micropython import const
18
19
import adafruit_connection_manager
21
22
22
23
23
24
# pylint: disable=too-many-instance-attributes
24
- class ESPSPI_WiFiManager :
25
+ class WiFiManager :
25
26
"""
26
27
A class to help manage the Wifi connection
27
28
"""
@@ -33,17 +34,23 @@ class ESPSPI_WiFiManager:
33
34
def __init__ (
34
35
self ,
35
36
esp ,
36
- secrets ,
37
+ ssid ,
38
+ password = None ,
39
+ * ,
40
+ enterprise_ident = None ,
41
+ enterprise_user = None ,
37
42
status_pixel = None ,
38
43
attempts = 2 ,
39
44
connection_type = NORMAL ,
40
45
debug = False ,
41
46
):
42
47
"""
43
48
: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.
47
54
:param status_pixel: (Optional) The pixel device - A NeoPixel, DotStar,
48
55
or RGB LED (default=None). The status LED, if given, turns red when
49
56
attempting to connect to a Wi-Fi network or create an access point,
@@ -57,8 +64,8 @@ def __init__(
57
64
# Read the settings
58
65
self .esp = esp
59
66
self .debug = debug
60
- self .ssid = secrets [ " ssid" ]
61
- self .password = secrets . get ( " password" , None )
67
+ self .ssid = ssid
68
+ self .password = password
62
69
self .attempts = attempts
63
70
self ._connection_type = connection_type
64
71
self .statuspix = status_pixel
@@ -70,11 +77,11 @@ def __init__(
70
77
ssl_context = adafruit_connection_manager .get_radio_ssl_context (self .esp )
71
78
self ._requests = adafruit_requests .Session (pool , ssl_context )
72
79
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
78
85
79
86
# pylint: enable=too-many-arguments
80
87
@@ -97,9 +104,9 @@ def connect(self):
97
104
print ("MAC addr:" , [hex (i ) for i in self .esp .MAC_address ])
98
105
for access_pt in self .esp .scan_networks ():
99
106
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 :
101
108
self .connect_normal ()
102
- elif self ._connection_type == ESPSPI_WiFiManager .ENTERPRISE :
109
+ elif self ._connection_type == WiFiManager .ENTERPRISE :
103
110
self .connect_enterprise ()
104
111
else :
105
112
raise TypeError ("Invalid WiFi connection type specified" )
@@ -347,3 +354,53 @@ def signal_strength(self):
347
354
if not self .esp .is_connected :
348
355
self .connect ()
349
356
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