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,22 @@ 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 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.
47
53
:param status_pixel: (Optional) The pixel device - A NeoPixel, DotStar,
48
54
or RGB LED (default=None). The status LED, if given, turns red when
49
55
attempting to connect to a Wi-Fi network or create an access point,
@@ -57,8 +63,8 @@ def __init__(
57
63
# Read the settings
58
64
self .esp = esp
59
65
self .debug = debug
60
- self .ssid = secrets [ " ssid" ]
61
- self .password = secrets . get ( " password" , None )
66
+ self .ssid = ssid
67
+ self .password = password
62
68
self .attempts = attempts
63
69
self ._connection_type = connection_type
64
70
self .statuspix = status_pixel
@@ -70,11 +76,11 @@ def __init__(
70
76
ssl_context = adafruit_connection_manager .get_radio_ssl_context (self .esp )
71
77
self ._requests = adafruit_requests .Session (pool , ssl_context )
72
78
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
78
84
79
85
# pylint: enable=too-many-arguments
80
86
@@ -97,9 +103,9 @@ def connect(self):
97
103
print ("MAC addr:" , [hex (i ) for i in self .esp .MAC_address ])
98
104
for access_pt in self .esp .scan_networks ():
99
105
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 :
101
107
self .connect_normal ()
102
- elif self ._connection_type == ESPSPI_WiFiManager .ENTERPRISE :
108
+ elif self ._connection_type == WiFiManager .ENTERPRISE :
103
109
self .connect_enterprise ()
104
110
else :
105
111
raise TypeError ("Invalid WiFi connection type specified" )
@@ -347,3 +353,57 @@ def signal_strength(self):
347
353
if not self .esp .is_connected :
348
354
self .connect ()
349
355
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
+ # pylint: disable=too-many-arguments
365
+ def __init__ (
366
+ self ,
367
+ esp ,
368
+ secrets ,
369
+ status_pixel = None ,
370
+ attempts = 2 ,
371
+ connection_type = WiFiManager .NORMAL ,
372
+ debug = False ,
373
+ ):
374
+ """
375
+ :param ESP_SPIcontrol esp: The ESP object we are using
376
+ :param dict secrets: The WiFi secrets dict
377
+ The use of secrets.py to populate the secrets dict is depreciated
378
+ in favor of using settings.toml.
379
+ :param status_pixel: (Optional) The pixel device - A NeoPixel, DotStar,
380
+ or RGB LED (default=None). The status LED, if given, turns red when
381
+ attempting to connect to a Wi-Fi network or create an access point,
382
+ turning green upon success. Additionally, if given, it will turn blue
383
+ when attempting an HTTP method or returning IP address, turning off
384
+ upon success.
385
+ :type status_pixel: NeoPixel, DotStar, or RGB LED
386
+ :param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=2)
387
+ :param const connection_type: (Optional) Type of WiFi connection: NORMAL or ENTERPRISE
388
+ """
389
+
390
+ warnings .warn (
391
+ "ESP32WiFiManager, which uses `secrets`, is deprecated. Use WifiManager instead and "
392
+ "fetch values from settings.toml with `os.getenv()`."
393
+ )
394
+
395
+ ssid = secrets .get ("ssid" )
396
+ password = secrets .get ("secrets" , None )
397
+ enterprise_ident = secrets .get ("ent_ident" , "" )
398
+ enterprise_user = secrets .get ("ent_user" )
399
+ super ().__init__ (
400
+ esp = esp ,
401
+ ssid = ssid ,
402
+ password = password ,
403
+ enterprise_ident = enterprise_ident ,
404
+ enterprise_user = enterprise_user ,
405
+ status_pixel = status_pixel ,
406
+ attempts = attempts ,
407
+ connection_type = connection_type ,
408
+ debug = debug ,
409
+ )
0 commit comments