@@ -38,20 +38,26 @@ class ESPSPI_WiFiManager:
3838 """
3939 A class to help manage the Wifi connection
4040 """
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 ):
4242 """
4343 :param ESP_SPIcontrol esp: The ESP object we are using
4444 :param dict secrets: The WiFi and Adafruit IO secrets dict (See examples)
4545 :param status_pixel: (Optional) The pixel device - A NeoPixel or DotStar (default=None)
4646 :type status_pixel: NeoPixel or DotStar
4747 :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
4849 """
4950 # Read the settings
5051 self ._esp = esp
5152 self .debug = False
5253 self .ssid = secrets ['ssid' ]
5354 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' ]
5459 self .attempts = attempts
60+ self .con_type = con_type
5561 requests .set_interface (self ._esp )
5662 self .statuspix = status_pixel
5763 self .pixel_status (0 )
@@ -76,21 +82,45 @@ def connect(self):
7682 for access_pt in self ._esp .scan_networks ():
7783 print ("\t %s\t \t RSSI: %d" % (str (access_pt ['ssid' ], 'utf-8' ), access_pt ['rssi' ]))
7884 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' ))
9192 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 )
94124
95125 def get (self , url , ** kw ):
96126 """
0 commit comments