Chapter 9
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<h1>Hello</h1>
|
||||
<p>World</p>
|
||||
@@ -0,0 +1,34 @@
|
||||
import robot_wifi
|
||||
|
||||
from adafruit_esp32spi import adafruit_esp32spi_wsgiserver
|
||||
from adafruit_wsgi.wsgi_app import WSGIApp
|
||||
|
||||
app = WSGIApp()
|
||||
|
||||
@app.route("/")
|
||||
def index(request):
|
||||
with open("hello.html") as fd:
|
||||
hello_html = fd.read()
|
||||
return 200, [('Content-Type',"text/html")], hello_html
|
||||
|
||||
print("Setting up wifi.")
|
||||
wifi, esp = robot_wifi.connect_to_wifi()
|
||||
server = adafruit_esp32spi_wsgiserver.WSGIServer(
|
||||
80,
|
||||
application=app
|
||||
)
|
||||
adafruit_esp32spi_wsgiserver.set_interface(esp)
|
||||
|
||||
print("Starting server")
|
||||
|
||||
server.start()
|
||||
ip_int = ".".join(str(int(n)) for n in esp.ip_address)
|
||||
print(f"IP Address is {ip_int}")
|
||||
while True:
|
||||
try:
|
||||
server.update_poll()
|
||||
# background task
|
||||
except:
|
||||
print("Shutting down wifi on failure. resetting ESP")
|
||||
wifi.reset()
|
||||
raise
|
||||
@@ -0,0 +1,32 @@
|
||||
import robot_wifi
|
||||
|
||||
from adafruit_esp32spi import adafruit_esp32spi_wsgiserver
|
||||
from adafruit_wsgi.wsgi_app import WSGIApp
|
||||
|
||||
app = WSGIApp()
|
||||
|
||||
@app.route("/")
|
||||
def index(request):
|
||||
return 200, [], "Hello world!"
|
||||
|
||||
print("Setting up wifi.")
|
||||
wifi, esp = robot_wifi.connect_to_wifi()
|
||||
server = adafruit_esp32spi_wsgiserver.WSGIServer(
|
||||
80,
|
||||
application=app
|
||||
)
|
||||
adafruit_esp32spi_wsgiserver.set_interface(esp)
|
||||
|
||||
print("Starting server")
|
||||
|
||||
server.start()
|
||||
ip_int = ".".join(str(int(n)) for n in esp.ip_address)
|
||||
print(f"IP Address is {ip_int}")
|
||||
while True:
|
||||
try:
|
||||
server.update_poll()
|
||||
# background task
|
||||
except:
|
||||
print("Shutting down wifi on failure. resetting ESP")
|
||||
wifi.reset()
|
||||
raise
|
||||
@@ -0,0 +1,25 @@
|
||||
import board
|
||||
import busio
|
||||
from digitalio import DigitalInOut
|
||||
from adafruit_esp32spi import adafruit_esp32spi
|
||||
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
|
||||
|
||||
try:
|
||||
from secrets import secrets
|
||||
except ImportError:
|
||||
print("WiFi secrets are kept in secrets.py, please add them there!")
|
||||
raise
|
||||
|
||||
|
||||
def connect_to_wifi():
|
||||
esp32_cs = DigitalInOut(board.GP10)
|
||||
esp32_ready = DigitalInOut(board.GP9)
|
||||
esp32_reset = DigitalInOut(board.GP8)
|
||||
|
||||
spi = busio.SPI(board.GP14, MOSI=board.GP11, MISO=board.GP12)
|
||||
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
|
||||
esp.reset()
|
||||
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets)
|
||||
wifi.connect()
|
||||
|
||||
return wifi, esp
|
||||
Reference in New Issue
Block a user