Skip to content

Commit 70af153

Browse files
authored
Update to current adafruit_httpserver & make response dynamic (#2)
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`.
1 parent 86009ef commit 70af153

File tree

13 files changed

+22
-8
lines changed

13 files changed

+22
-8
lines changed

circup_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
adafruit_requests==2.0.5

scripts/deploy.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ fi
2424
echo "Found device at $device_path"
2525

2626
echo 'Copying application code...'
27-
rsync --verbose --recursive --delete --checksum \
27+
rsync --verbose --recursive --delete --checksum --times --modify-window=1 \
2828
--include '/._*' --exclude '/.*' \
29-
--exclude '/boot_out.txt' --exclude '/settings.toml' \
29+
--exclude '/boot_out.txt' --exclude '/settings.toml' --exclude '/lib' \
3030
"$project_directory/src/" "$device_path"
3131
echo 'Finished copying application code'
32+
33+
echo 'Installing libraries with circup'
34+
circup install --requirement circup_requirements.txt
35+
echo 'Finished installing libraries with circup'

src/code.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@
77
import supervisor
88
import wifi
99

10-
from adafruit_httpserver.server import HTTPServer
10+
from adafruit_httpserver.server import Server as HTTPServer
11+
from adafruit_httpserver.response import Response
12+
13+
14+
def index(request):
15+
u = os.uname()
16+
return Response(
17+
request,
18+
content_type="text/plain",
19+
body=f"Hello from {u.machine} running CircuitPython {u.version}!\n",
20+
)
1121

1222

1323
def main() -> None:
@@ -24,7 +34,8 @@ def main() -> None:
2434
host = str(wifi.radio.ipv4_address)
2535
pool = socketpool.SocketPool(wifi.radio)
2636
http_server = HTTPServer(pool)
27-
http_server.start(host, port=80, root_path="public_html")
37+
http_server.route("/")(index)
38+
http_server.start(host, port=80)
2839

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

4052
print()
4153
print("The web server is listening on:")
-150 Bytes
Binary file not shown.
-891 Bytes
Binary file not shown.
-190 Bytes
Binary file not shown.
-2.58 KB
Binary file not shown.
-1.01 KB
Binary file not shown.
-1.86 KB
Binary file not shown.

src/lib/adafruit_httpserver/route.mpy

-338 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy