@@ -38,21 +38,27 @@ 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
61
+ self .con_type = con_type
56
62
requests .set_interface (self ._esp )
57
63
self .statuspix = status_pixel
58
64
self .pixel_status (0 )
@@ -77,21 +83,45 @@ def connect(self):
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' ]))
79
85
failure_count = 0
80
- while not self ._esp .is_connected :
81
- try :
82
- if self .debug :
83
- print ("Connecting to AP..." )
84
- self .pixel_status ((100 , 0 , 0 ))
85
- self ._esp .connect_AP (bytes (self .ssid , 'utf-8' ), bytes (self .password , 'utf-8' ))
86
- failure_count = 0
87
- self .pixel_status ((0 , 100 , 0 ))
88
- except (ValueError , RuntimeError ) as error :
89
- print ("Failed to connect, retrying\n " , error )
90
- failure_count += 1
91
- if failure_count >= self .attempts :
86
+ if self .con_type == 1 :
87
+ while not self ._esp .is_connected :
88
+ try :
89
+ if self .debug :
90
+ print ("Connecting to AP..." )
91
+ self .pixel_status ((100 , 0 , 0 ))
92
+ self ._esp .connect_AP (bytes (self .ssid , 'utf-8' ), bytes (self .password , 'utf-8' ))
92
93
failure_count = 0
93
- self .reset ()
94
- continue
94
+ self .pixel_status ((0 , 100 , 0 ))
95
+ except (ValueError , RuntimeError ) as error :
96
+ print ("Failed to connect, retrying\n " , error )
97
+ failure_count += 1
98
+ if failure_count >= self .attempts :
99
+ failure_count = 0
100
+ self .reset ()
101
+ continue
102
+ elif self .con_type == 2 :
103
+ self ._esp .wifi_set_network (bytes (self .ent_ssid , 'utf-8' ))
104
+ self ._esp .wifi_set_entidentity (bytes (self .ent_ident , 'utf-8' ))
105
+ self ._esp .wifi_set_entusername (bytes (self .ent_user , 'utf-8' ))
106
+ self ._esp .wifi_set_entpassword (bytes (self .ent_passwd , 'utf-8' ))
107
+ self ._esp .wifi_set_entenable ()
108
+ while not self ._esp .is_connected :
109
+ try :
110
+ if self .debug :
111
+ print ("Connecting to WPA2 Enterprise AP..." )
112
+ self .pixel_status ((100 , 0 , 0 ))
113
+ failure_count = 0
114
+ self .pixel_status ((0 , 100 , 0 ))
115
+ except (ValueError , RuntimeError ) as error :
116
+ print ("Failed to connect, retrying\n " , error )
117
+ failure_count += 1
118
+ if failure_count >= self .attempts :
119
+ failure_count = 0
120
+ self .reset ()
121
+ continue
122
+ else :
123
+ print ("Invalid connection type! Exiting..." )
124
+ exit (1 )
95
125
96
126
def get (self , url , ** kw ):
97
127
"""
0 commit comments