|
26 | 26 |
|
27 | 27 | print("ESP32 SPI simple web server test!")
|
28 | 28 |
|
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) |
33 | 38 |
|
34 | 39 | spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
|
35 | 40 | 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
|
164 | 169 | # Here we create our application, setting the static directory location
|
165 | 170 | # and registering the above request_handlers for specific HTTP requests
|
166 | 171 | # 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) |
168 | 185 | web_app.on("GET", "/led_on", led_on)
|
169 | 186 | web_app.on("GET", "/led_off", led_off)
|
170 | 187 | web_app.on("POST", "/ajax/ledcolor", led_color)
|
|
0 commit comments