Skip to content

Commit e9bbf95

Browse files
committed
Updated WPA2 Enterprise example code to check ESP32 firmware version; updated README.rst to recommended checking version dependencies in example code.
1 parent 4110a44 commit e9bbf95

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

README.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ Introduction
1313
:target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_ESP32SPI
1414
:alt: Build Status
1515

16-
CircuitPython driver library for using ESP32 as WiFi co-processor using SPI
16+
CircuitPython driver library for using ESP32 as WiFi co-processor using SPI.
17+
The companion firmware `is available on GitHub
18+
<https://github.com/adafruit/nina-fw>`_. Please be sure to check the example code for
19+
any specific firmware version dependencies that may exist.
1720

1821

1922
Dependencies

examples/esp32spi_wpa2ent_simpletest.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
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
110
import time
211
import board
312
import busio
@@ -6,6 +15,14 @@
615
from adafruit_esp32spi import adafruit_esp32spi
716
import adafruit_esp32spi.adafruit_esp32spi_requests as requests
817

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+
926
print("ESP32 SPI WPA2 Enterprise test")
1027

1128
# For running on the PyPortal, use this block
@@ -14,9 +31,7 @@
1431
esp32_reset = DigitalInOut(board.ESP_RESET)
1532

1633
# 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.
2035
#esp32_cs = DigitalInOut(board.D8)
2136
#esp32_ready = DigitalInOut(board.D5)
2237
#esp32_reset = DigitalInOut(board.D7)
@@ -28,10 +43,21 @@
2843

2944
if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
3045
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+
3252
print("MAC addr:", [hex(i) for i in esp.MAC_address])
3353

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+
3458
# 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.
3561
esp.wifi_set_network(b'YOUR_SSID_HERE')
3662

3763
# If your WPA2 Enterprise network requires an anonymous

0 commit comments

Comments
 (0)