Skip to content

Commit

Permalink
Update to current adafruit_httpserver & make response dynamic (#2)
Browse files Browse the repository at this point in the history
Together with adafruit/circuitpython#8932 this https server is verified to work on `Adafruit MatrixPortal S3 with ESP32S3 running 9.0.0-beta.0-38-g0c3b62fac2-dirty on 2024-02-16`.
  • Loading branch information
jepler authored Feb 20, 2024
1 parent 86009ef commit 70af153
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions circup_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
adafruit_requests==2.0.5
8 changes: 6 additions & 2 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ fi
echo "Found device at $device_path"

echo 'Copying application code...'
rsync --verbose --recursive --delete --checksum \
rsync --verbose --recursive --delete --checksum --times --modify-window=1 \
--include '/._*' --exclude '/.*' \
--exclude '/boot_out.txt' --exclude '/settings.toml' \
--exclude '/boot_out.txt' --exclude '/settings.toml' --exclude '/lib' \
"$project_directory/src/" "$device_path"
echo 'Finished copying application code'

echo 'Installing libraries with circup'
circup install --requirement circup_requirements.txt
echo 'Finished installing libraries with circup'
18 changes: 15 additions & 3 deletions src/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@
import supervisor
import wifi

from adafruit_httpserver.server import HTTPServer
from adafruit_httpserver.server import Server as HTTPServer
from adafruit_httpserver.response import Response


def index(request):
u = os.uname()
return Response(
request,
content_type="text/plain",
body=f"Hello from {u.machine} running CircuitPython {u.version}!\n",
)


def main() -> None:
Expand All @@ -24,7 +34,8 @@ def main() -> None:
host = str(wifi.radio.ipv4_address)
pool = socketpool.SocketPool(wifi.radio)
http_server = HTTPServer(pool)
http_server.start(host, port=80, root_path="public_html")
http_server.route("/")(index)
http_server.start(host, port=80)

ssl_context = ssl.create_default_context()
# The Pico is the server and does not require a certificate from the client, so disable
Expand All @@ -35,7 +46,8 @@ def main() -> None:
)
tls_pool = TLSServerSocketPool(pool, ssl_context)
https_server = HTTPServer(tls_pool)
https_server.start(host, port=443, root_path="public_html")
https_server.route("/")(index)
https_server.start(host, port=443)

print()
print("The web server is listening on:")
Expand Down
Binary file removed src/lib/adafruit_httpserver/__init__.mpy
Binary file not shown.
Binary file removed src/lib/adafruit_httpserver/headers.mpy
Binary file not shown.
Binary file removed src/lib/adafruit_httpserver/methods.mpy
Binary file not shown.
Binary file removed src/lib/adafruit_httpserver/mime_type.mpy
Binary file not shown.
Binary file removed src/lib/adafruit_httpserver/request.mpy
Binary file not shown.
Binary file removed src/lib/adafruit_httpserver/response.mpy
Binary file not shown.
Binary file removed src/lib/adafruit_httpserver/route.mpy
Binary file not shown.
Binary file removed src/lib/adafruit_httpserver/server.mpy
Binary file not shown.
Binary file removed src/lib/adafruit_httpserver/status.mpy
Binary file not shown.
3 changes: 0 additions & 3 deletions src/public_html/index.html

This file was deleted.

0 comments on commit 70af153

Please sign in to comment.