@@ -38,22 +38,28 @@ class ESPSPI_WiFiManager:
38
38
"""
39
39
A class to help manage the Wifi connection
40
40
"""
41
- def __init__ (self , esp , secrets , status_pixel = None , attempts = 2 ):
41
+ def __init__ (self , esp , secrets , status_pixel = None , attempts = 2 , con_type = 1 ):
42
42
"""
43
43
:param ESP_SPIcontrol esp: The ESP object we are using
44
44
:param dict secrets: The WiFi and Adafruit IO secrets dict (See examples)
45
45
:param status_pixel: (Optional) The pixel device - A NeoPixel, DotStar,
46
46
or RGB LED (default=None)
47
47
:type status_pixel: NeoPixel, DotStar, or RGB LED
48
48
:param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=2)
49
+ :param int con_type: (Optional) Type of WiFi connection to make: normal=1, WPA2 Enterprise=2
49
50
"""
50
51
# Read the settings
51
52
self .esp = esp
52
53
self .debug = False
53
54
self .ssid = secrets ['ssid' ]
54
55
self .password = secrets ['password' ]
56
+ self .ent_ssid = secrets ['ent_ssid' ]
57
+ self .ent_ident = secrets ['ent_ident' ]
58
+ self .ent_user = secrets ['ent_user' ]
59
+ self .ent_passwd = secrets ['ent_passwd' ]
55
60
self .attempts = attempts
56
61
requests .set_interface (self .esp )
62
+ self .con_type = con_type
57
63
self .statuspix = status_pixel
58
64
self .pixel_status (0 )
59
65
@@ -76,6 +82,17 @@ def connect(self):
76
82
print ("MAC addr:" , [hex (i ) for i in self .esp .MAC_address ])
77
83
for access_pt in self .esp .scan_networks ():
78
84
print ("\t %s\t \t RSSI: %d" % (str (access_pt ['ssid' ], 'utf-8' ), access_pt ['rssi' ]))
85
+ if self ._connection_type == ESPSPI_WiFiManager .NORMAL :
86
+ self .connect_normal ()
87
+ elif self ._connection_type == ESPSPI_WiFiManager .ENTERPRISE :
88
+ self .connect_enterprise ()
89
+ else :
90
+ raise TypeError ("Invalid WiFi connection type specified" )
91
+
92
+ def connect_normal (self ):
93
+ """
94
+ Attempt a regular style WiFi connection
95
+ """
79
96
failure_count = 0
80
97
while not self .esp .is_connected :
81
98
try :
@@ -93,6 +110,33 @@ def connect(self):
93
110
self .reset ()
94
111
continue
95
112
113
+ def connect_enterprise (self ):
114
+ """
115
+ Attempt an enterprise style WiFi connection
116
+ """
117
+ failure_count = 0
118
+ self .esp .wifi_set_network (bytes (self .ent_ssid , 'utf-8' ))
119
+ self .esp .wifi_set_entidentity (bytes (self .ent_ident , 'utf-8' ))
120
+ self .esp .wifi_set_entusername (bytes (self .ent_user , 'utf-8' ))
121
+ self .esp .wifi_set_entpassword (bytes (self .ent_password , 'utf-8' ))
122
+ self .esp .wifi_set_entenable ()
123
+ while not self .esp .is_connected :
124
+ try :
125
+ if self .debug :
126
+ print ("Waiting for the ESP32 to connect to the WPA2 Enterprise AP..." )
127
+ self .pixel_status ((100 , 0 , 0 ))
128
+ sleep (1 )
129
+ failure_count = 0
130
+ self .pixel_status ((0 , 100 , 0 ))
131
+ sleep (1 )
132
+ except (ValueError , RuntimeError ) as error :
133
+ print ("Failed to connect, retrying\n " , error )
134
+ failure_count += 1
135
+ if failure_count >= self .attempts :
136
+ failure_count = 0
137
+ self .reset ()
138
+ continue
139
+
96
140
def get (self , url , ** kw ):
97
141
"""
98
142
Pass the Get request to requests and update status LED
0 commit comments