34
34
from adafruit_esp32spi import adafruit_esp32spi
35
35
import adafruit_esp32spi .adafruit_esp32spi_requests as requests
36
36
37
+ class WiFiConnType : # pylint: disable=too-few-public-methods
38
+ """An enum-like class representing the different types of WiFi connections
39
+ that can be made. The values can be referenced like ``WiFiConnType.normal``.
40
+ Possible values are
41
+ - ``ThermocoupleType.normal``
42
+ - ``ThermocoupleType.enterprise``
43
+ """
44
+ # pylint: disable=invalid-name
45
+ normal = 1
46
+ enterprise = 2
47
+
37
48
class ESPSPI_WiFiManager :
38
49
"""
39
50
A class to help manage the Wifi connection
40
51
"""
41
- def __init__ (self , esp , secrets , status_pixel = None , attempts = 2 , con_type = 1 ):
52
+ def __init__ (self , esp , secrets , status_pixel = None , attempts = 2 , wificonntype = WiFiConnType . normal ):
42
53
"""
43
54
:param ESP_SPIcontrol esp: The ESP object we are using
44
55
:param dict secrets: The WiFi and Adafruit IO secrets dict (See examples)
45
56
:param status_pixel: (Optional) The pixel device - A NeoPixel or DotStar (default=None)
46
57
:type status_pixel: NeoPixel or DotStar
47
58
:param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=2)
48
- :param int con_type: (Optional) Type of WiFi connection to make: normal=1, WPA2 Enterprise=2
59
+ :param const con_type: (Optional) Type of WiFi connection: normal=1, WPA2 Enterprise=2
60
+ :param ~adafruit_esp32spi_wifimanager.WiFiConnType wificonntype: The type of WiFi \
61
+ connection to make. The default is "normal".
49
62
"""
50
63
# Read the settings
51
64
self ._esp = esp
@@ -57,7 +70,7 @@ def __init__(self, esp, secrets, status_pixel=None, attempts=2, con_type=1):
57
70
self .ent_user = secrets ['ent_user' ]
58
71
self .ent_passwd = secrets ['ent_passwd' ]
59
72
self .attempts = attempts
60
- self .con_type = con_type
73
+ self .wificonntype = wificonntype
61
74
requests .set_interface (self ._esp )
62
75
self .statuspix = status_pixel
63
76
self .pixel_status (0 )
@@ -82,7 +95,7 @@ def connect(self):
82
95
for access_pt in self ._esp .scan_networks ():
83
96
print ("\t %s\t \t RSSI: %d" % (str (access_pt ['ssid' ], 'utf-8' ), access_pt ['rssi' ]))
84
97
failure_count = 0
85
- if self .con_type == 1 :
98
+ if self .wificonntype == WiFiConnType . normal :
86
99
while not self ._esp .is_connected :
87
100
try :
88
101
if self .debug :
@@ -98,7 +111,7 @@ def connect(self):
98
111
failure_count = 0
99
112
self .reset ()
100
113
continue
101
- elif self .con_type == 2 :
114
+ elif self .wificonntype == WiFiConnType . enterprise :
102
115
self ._esp .wifi_set_network (bytes (self .ent_ssid , 'utf-8' ))
103
116
self ._esp .wifi_set_entidentity (bytes (self .ent_ident , 'utf-8' ))
104
117
self ._esp .wifi_set_entusername (bytes (self .ent_user , 'utf-8' ))
0 commit comments