@@ -38,20 +38,26 @@ 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 or DotStar (default=None)
46
46
:type status_pixel: NeoPixel or DotStar
47
47
: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
48
49
"""
49
50
# Read the settings
50
51
self ._esp = esp
51
52
self .debug = False
52
53
self .ssid = secrets ['ssid' ]
53
54
self .password = secrets ['password' ]
55
+ self .ent_ssid = secrets ['ent_ssid' ]
56
+ self .ent_ident = secrets ['ent_ident' ]
57
+ self .ent_user = secrets ['ent_user' ]
58
+ self .ent_passwd = secrets ['ent_passwd' ]
54
59
self .attempts = attempts
60
+ self .con_type = con_type
55
61
requests .set_interface (self ._esp )
56
62
self .statuspix = status_pixel
57
63
self .pixel_status (0 )
@@ -76,21 +82,45 @@ def connect(self):
76
82
for access_pt in self ._esp .scan_networks ():
77
83
print ("\t %s\t \t RSSI: %d" % (str (access_pt ['ssid' ], 'utf-8' ), access_pt ['rssi' ]))
78
84
failure_count = 0
79
- while not self ._esp .is_connected :
80
- try :
81
- if self .debug :
82
- print ("Connecting to AP..." )
83
- self .pixel_status ((100 , 0 , 0 ))
84
- self ._esp .connect_AP (bytes (self .ssid , 'utf-8' ), bytes (self .password , 'utf-8' ))
85
- failure_count = 0
86
- self .pixel_status ((0 , 100 , 0 ))
87
- except (ValueError , RuntimeError ) as error :
88
- print ("Failed to connect, retrying\n " , error )
89
- failure_count += 1
90
- if failure_count >= self .attempts :
85
+ if self .con_type == 1 :
86
+ while not self ._esp .is_connected :
87
+ try :
88
+ if self .debug :
89
+ print ("Connecting to AP..." )
90
+ self .pixel_status ((100 , 0 , 0 ))
91
+ self ._esp .connect_AP (bytes (self .ssid , 'utf-8' ), bytes (self .password , 'utf-8' ))
91
92
failure_count = 0
92
- self .reset ()
93
- continue
93
+ self .pixel_status ((0 , 100 , 0 ))
94
+ except (ValueError , RuntimeError ) as error :
95
+ print ("Failed to connect, retrying\n " , error )
96
+ failure_count += 1
97
+ if failure_count >= self .attempts :
98
+ failure_count = 0
99
+ self .reset ()
100
+ continue
101
+ elif self .con_type == 2 :
102
+ self ._esp .wifi_set_network (bytes (self .ent_ssid , 'utf-8' ))
103
+ self ._esp .wifi_set_entidentity (bytes (self .ent_ident , 'utf-8' ))
104
+ self ._esp .wifi_set_entusername (bytes (self .ent_user , 'utf-8' ))
105
+ self ._esp .wifi_set_entpassword (bytes (self .ent_passwd , 'utf-8' ))
106
+ self ._esp .wifi_set_entenable ()
107
+ while not self ._esp .is_connected :
108
+ try :
109
+ if self .debug :
110
+ print ("Connecting to WPA2 Enterprise AP..." )
111
+ self .pixel_status ((100 , 0 , 0 ))
112
+ failure_count = 0
113
+ self .pixel_status ((0 , 100 , 0 ))
114
+ except (ValueError , RuntimeError ) as error :
115
+ print ("Failed to connect, retrying\n " , error )
116
+ failure_count += 1
117
+ if failure_count >= self .attempts :
118
+ failure_count = 0
119
+ self .reset ()
120
+ continue
121
+ else :
122
+ print ("Invalid connection type! Exiting..." )
123
+ exit (1 )
94
124
95
125
def get (self , url , ** kw ):
96
126
"""
0 commit comments