Skip to content

Commit a93c099

Browse files
committed
Address PR comments
1 parent 473f850 commit a93c099

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

examples/esp32spi_wsgiserver.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@
2626

2727
print("ESP32 SPI simple web server test!")
2828

29-
esp32_cs = DigitalInOut(board.D10)
30-
esp32_ready = DigitalInOut(board.D9)
31-
esp32_reset = DigitalInOut(board.D7)
32-
esp32_gpio0 = DigitalInOut(board.D12)
29+
# If you are using a board with pre-defined ESP32 Pins:
30+
esp32_cs = DigitalInOut(board.ESP_CS)
31+
esp32_ready = DigitalInOut(board.ESP_BUSY)
32+
esp32_reset = DigitalInOut(board.ESP_RESET)
33+
34+
# If you have an externally connected ESP32:
35+
# esp32_cs = DigitalInOut(board.D9)
36+
# esp32_ready = DigitalInOut(board.D10)
37+
# esp32_reset = DigitalInOut(board.D5)
3338

3439
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
3540
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset, gpio0_pin=esp32_gpio0) # pylint: disable=line-too-long
@@ -164,7 +169,19 @@ def led_color(environ): # pylint: disable=unused-argument
164169
# Here we create our application, setting the static directory location
165170
# and registering the above request_handlers for specific HTTP requests
166171
# we want to listen and respond to.
167-
web_app = SimpleWSGIApplication(static_dir="/static")
172+
static_dir = "/static"
173+
try:
174+
static_files = os.listdir(static_dir)
175+
if "index.html" not in static_files:
176+
raise RuntimeError("""
177+
This example depends on an index.html, but it isn't present.
178+
Please add it to the {0} directory""".format(static_dir))
179+
except (OSError) as e:
180+
raise RuntimeError("""
181+
This example depends on a static asset directory.
182+
Please create one named {0} in the root of the device filesystem.""".format(static_dir))
183+
184+
web_app = SimpleWSGIApplication(static_dir=static_dir)
168185
web_app.on("GET", "/led_on", led_on)
169186
web_app.on("GET", "/led_off", led_off)
170187
web_app.on("POST", "/ajax/ledcolor", led_color)

0 commit comments

Comments
 (0)