|
| 1 | +# Example code implementing WPA2 Enterprise mode |
| 2 | +# |
| 3 | +# This code requires firmware version 1.3.0, or newer, running |
| 4 | +# on the ESP32 WiFi co-processor. The latest firmware, and wiring |
| 5 | +# info if you are using something other than a PyPortal, can be found |
| 6 | +# in the Adafruit Learning System: |
| 7 | +# https://learn.adafruit.com/adding-a-wifi-co-processor-to-circuitpython-esp8266-esp32/firmware-files#esp32-only-spi-firmware-3-8 |
| 8 | + |
| 9 | +import re |
1 | 10 | import time
|
2 | 11 | import board
|
3 | 12 | import busio
|
|
6 | 15 | from adafruit_esp32spi import adafruit_esp32spi
|
7 | 16 | import adafruit_esp32spi.adafruit_esp32spi_requests as requests
|
8 | 17 |
|
| 18 | +# Version number comparison code. Credit to gnud on stackoverflow |
| 19 | +# (https://stackoverflow.com/a/1714190), swapping out cmp() to |
| 20 | +# support Python 3.x and thus, CircuitPython |
| 21 | +def version_compare(version1, version2): |
| 22 | + def normalize(v): |
| 23 | + return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")] |
| 24 | + return (normalize(version1) > normalize(version2)) - (normalize(version1) < normalize(version2)) |
| 25 | + |
9 | 26 | print("ESP32 SPI WPA2 Enterprise test")
|
10 | 27 |
|
11 | 28 | # For running on the PyPortal, use this block
|
|
14 | 31 | esp32_reset = DigitalInOut(board.ESP_RESET)
|
15 | 32 |
|
16 | 33 | # For a board that doesn't have the ESP pin definitions, use this block and
|
17 |
| -# set the pins as needed. To connect your board to an ESP32 HUZZAH, here |
18 |
| -# are the pin-outs on the HUZZAH32: |
19 |
| -# https://learn.adafruit.com/adding-a-wifi-co-processor-to-circuitpython-esp8266-esp32/firmware-files#esp32-only-spi-firmware-3-8 |
| 34 | +# set the pins as needed. |
20 | 35 | #esp32_cs = DigitalInOut(board.D8)
|
21 | 36 | #esp32_ready = DigitalInOut(board.D5)
|
22 | 37 | #esp32_reset = DigitalInOut(board.D7)
|
|
28 | 43 |
|
29 | 44 | if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
|
30 | 45 | print("ESP32 found and in idle mode")
|
31 |
| -print("Firmware vers.", esp.firmware_version) |
| 46 | + |
| 47 | +# Get the ESP32 fw version number, remove trailing byte off the returned bytearray |
| 48 | +# and then convert it to a string for prettier printing and later comparison |
| 49 | +firmware_version = ''.join([chr(b) for b in esp.firmware_version[:-1]]) |
| 50 | +print("Firmware vers.", firmware_version) |
| 51 | + |
32 | 52 | print("MAC addr:", [hex(i) for i in esp.MAC_address])
|
33 | 53 |
|
| 54 | +# WPA2 Enterprise support was added in fw ver 1.3.0. Check that the ESP32 |
| 55 | +# is running at least that version, otherwise, bail out |
| 56 | +assert version_compare(firmware_version, "1.3.0") >= 0, "Inforrect ESP32 firmware version detected. v1.3.0 or greater required" |
| 57 | + |
34 | 58 | # Set up the SSID you would like to connect to
|
| 59 | +# Note that we need to call wifi_set_network prior |
| 60 | +# to calling wifi_set_enable. |
35 | 61 | esp.wifi_set_network(b'YOUR_SSID_HERE')
|
36 | 62 |
|
37 | 63 | # If your WPA2 Enterprise network requires an anonymous
|
|
0 commit comments