Skip to content

Update to current adafruit_httpserver & make response dynamic #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.