Skip to content

Adding WPA2 Enterprise support to the WiFi manager library #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 46 commits into from
Jul 15, 2019
Merged
Changes from 2 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
8e65459
Chunk buffer sends into 64 byte chunks
martymcguire Mar 13, 2019
9cade63
rm temp vars. replace buffer slice w/ memoryview.
martymcguire Mar 13, 2019
79425a6
Fixed infinite loop when socket readline fails
ZachNo May 5, 2019
bf54a08
Update adafruit_esp32spi/adafruit_esp32spi_socket.py
ZachNo May 19, 2019
7386534
Adding WPA2 Enterprise support to the WiFi manager library
docmollo May 19, 2019
d8f4ad2
Added an enum-like class for the WiFi connection type and refactored …
docmollo May 19, 2019
8e2b787
Replaced enum-like class with 2 constants; various fix-ups based on P…
docmollo May 22, 2019
ac4aee5
Merge pull request #42 from ZachNo/socket_hang_fix
ladyada May 25, 2019
c25157e
Make timeout a keyword argument
anecdata Jun 4, 2019
868dd5e
Merge pull request #50 from anecdata/master
makermelissa Jun 4, 2019
4df8144
add first mock api, blinks!
Jun 6, 2019
7772894
add valid pin tupleset check before initialization, raise error
Jun 6, 2019
00e7f97
drop all pull functionality since we dont have it defined in adafruit…
Jun 6, 2019
5e97cb1
add switch_to_x methods, docstrings
Jun 6, 2019
6a0c036
pylinting - 8.79/10, look at drivemode/direction classes...
Jun 6, 2019
4923344
checking in digitalio, ready
Jun 6, 2019
8599c01
add credit to where credit is due :)
Jun 6, 2019
e199972
Merge pull request #51 from brentru/mock-pwmout-digitalio
brentru Jun 6, 2019
6fcb231
Adding pwmout back in
Jun 7, 2019
64ca443
correct pin in attrerror, fixup docstrings
Jun 7, 2019
c916224
set freq
Jun 7, 2019
596b879
frequency should return, not raise
Jun 7, 2019
46b4dea
Merge pull request #52 from brentru/add-pwmout-implementation
brentru Jun 7, 2019
d21b709
add an externally defined rgbled status_led to _wifimanager
Jun 11, 2019
aeae91e
test the pixel attributes within pixel_status
Jun 11, 2019
92182ea
Merge pull request #53 from brentru/expose-rgbled-status-wifimanager
ladyada Jun 11, 2019
0d7c5b5
Adding WPA2 Enterprise support to the WiFi manager library
docmollo May 19, 2019
15ea3cc
Added an enum-like class for the WiFi connection type and refactored …
docmollo May 19, 2019
1eca01c
Replaced enum-like class with 2 constants; various fix-ups based on P…
docmollo May 22, 2019
1ff8edf
Refactored wifimanager connect function into 3 separate functions; re…
docmollo Jun 16, 2019
e01c762
fixing merge conflicts
docmollo Jun 16, 2019
4190bc3
fix the failure_count issue...sorry about that!
docmollo Jun 19, 2019
54bcb5a
make ._esp public
Jul 11, 2019
a23026d
Merge pull request #60 from brentru/make-esp-object-public
brentru Jul 11, 2019
8f964cc
Merge pull request #29 from martymcguire/mm-chunk-socket-sends
siddacious Jul 11, 2019
1e77ef5
merged conflicts
docmollo Jul 13, 2019
a492dda
merged conflicts
docmollo Jul 13, 2019
bce6bfa
merged conflicts
docmollo Jul 13, 2019
cbc7901
merged conflicts
docmollo Jul 13, 2019
447955a
merged conflicts
docmollo Jul 13, 2019
0c07ceb
merged conflicts
docmollo Jul 13, 2019
5931c1b
merged conflicts
docmollo Jul 13, 2019
7bc0ec6
merged conflicts
docmollo Jul 13, 2019
bb679e8
fix a regression due to the rebase'ing...
docmollo Jul 14, 2019
5c7a735
more fix-ups from rebase; fixed param defs in __init__
docmollo Jul 14, 2019
c89d13e
fixing more issues
docmollo Jul 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 58 additions & 15 deletions adafruit_esp32spi/adafruit_esp32spi_wifimanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,43 @@
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_esp32spi.adafruit_esp32spi_requests as requests

class WiFiConnType: # pylint: disable=too-few-public-methods
"""An enum-like class representing the different types of WiFi connections
that can be made. The values can be referenced like ``WiFiConnType.normal``.
Possible values are
- ``ThermocoupleType.normal``
- ``ThermocoupleType.enterprise``
"""
# pylint: disable=invalid-name
normal = 1
enterprise = 2

class ESPSPI_WiFiManager:
"""
A class to help manage the Wifi connection
"""
def __init__(self, esp, secrets, status_pixel=None, attempts=2):
def __init__(self, esp, secrets, status_pixel=None, attempts=2, wificonntype=WiFiConnType.normal):
"""
:param ESP_SPIcontrol esp: The ESP object we are using
:param dict secrets: The WiFi and Adafruit IO secrets dict (See examples)
:param status_pixel: (Optional) The pixel device - A NeoPixel or DotStar (default=None)
:type status_pixel: NeoPixel or DotStar
:param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=2)
:param const con_type: (Optional) Type of WiFi connection: normal=1, WPA2 Enterprise=2
:param ~adafruit_esp32spi_wifimanager.WiFiConnType wificonntype: The type of WiFi \
connection to make. The default is "normal".
"""
# Read the settings
self._esp = esp
self.debug = False
self.ssid = secrets['ssid']
self.password = secrets['password']
self.ent_ssid = secrets['ent_ssid']
self.ent_ident = secrets['ent_ident']
self.ent_user = secrets['ent_user']
self.ent_passwd = secrets['ent_passwd']
self.attempts = attempts
self.wificonntype = wificonntype
requests.set_interface(self._esp)
self.statuspix = status_pixel
self.pixel_status(0)
Expand All @@ -76,21 +95,45 @@ def connect(self):
for access_pt in self._esp.scan_networks():
print("\t%s\t\tRSSI: %d" % (str(access_pt['ssid'], 'utf-8'), access_pt['rssi']))
failure_count = 0
while not self._esp.is_connected:
try:
if self.debug:
print("Connecting to AP...")
self.pixel_status((100, 0, 0))
self._esp.connect_AP(bytes(self.ssid, 'utf-8'), bytes(self.password, 'utf-8'))
failure_count = 0
self.pixel_status((0, 100, 0))
except (ValueError, RuntimeError) as error:
print("Failed to connect, retrying\n", error)
failure_count += 1
if failure_count >= self.attempts:
if self.wificonntype == WiFiConnType.normal:
while not self._esp.is_connected:
try:
if self.debug:
print("Connecting to AP...")
self.pixel_status((100, 0, 0))
self._esp.connect_AP(bytes(self.ssid, 'utf-8'), bytes(self.password, 'utf-8'))
failure_count = 0
self.pixel_status((0, 100, 0))
except (ValueError, RuntimeError) as error:
print("Failed to connect, retrying\n", error)
failure_count += 1
if failure_count >= self.attempts:
failure_count = 0
self.reset()
continue
elif self.wificonntype == WiFiConnType.enterprise:
self._esp.wifi_set_network(bytes(self.ent_ssid, 'utf-8'))
self._esp.wifi_set_entidentity(bytes(self.ent_ident, 'utf-8'))
self._esp.wifi_set_entusername(bytes(self.ent_user, 'utf-8'))
self._esp.wifi_set_entpassword(bytes(self.ent_passwd, 'utf-8'))
self._esp.wifi_set_entenable()
while not self._esp.is_connected:
try:
if self.debug:
print("Connecting to WPA2 Enterprise AP...")
self.pixel_status((100, 0, 0))
failure_count = 0
self.reset()
continue
self.pixel_status((0, 100, 0))
except (ValueError, RuntimeError) as error:
print("Failed to connect, retrying\n", error)
failure_count += 1
if failure_count >= self.attempts:
failure_count = 0
self.reset()
continue
else:
print("Invalid connection type! Exiting...")
exit(1)

def get(self, url, **kw):
"""
Expand Down