Skip to content

Commit 1e77ef5

Browse files
committed
merged conflicts
1 parent 8f964cc commit 1e77ef5

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

adafruit_esp32spi/adafruit_esp32spi_wifimanager.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,28 @@ 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, DotStar,
4646
or RGB LED (default=None)
4747
:type status_pixel: NeoPixel, DotStar, or RGB LED
4848
: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
4950
"""
5051
# Read the settings
5152
self.esp = esp
5253
self.debug = False
5354
self.ssid = secrets['ssid']
5455
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']
5560
self.attempts = attempts
5661
requests.set_interface(self.esp)
62+
self.con_type = con_type
5763
self.statuspix = status_pixel
5864
self.pixel_status(0)
5965

@@ -76,6 +82,17 @@ def connect(self):
7682
print("MAC addr:", [hex(i) for i in self.esp.MAC_address])
7783
for access_pt in self.esp.scan_networks():
7884
print("\t%s\t\tRSSI: %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+
"""
7996
failure_count = 0
8097
while not self.esp.is_connected:
8198
try:
@@ -93,6 +110,33 @@ def connect(self):
93110
self.reset()
94111
continue
95112

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+
96140
def get(self, url, **kw):
97141
"""
98142
Pass the Get request to requests and update status LED

0 commit comments

Comments
 (0)