Compare commits

..

6 commits

Author SHA1 Message Date
dc65439632 Perform circup installation from a requirements file
.. generated by "circup freeze"
2024-02-20 09:21:31 -06:00
30488c93e1 fix circup invocation to use double dash 2024-02-20 09:16:26 -06:00
d851c9a74a Use long option names with rsync 2024-02-20 09:16:05 -06:00
1fe1708b86
Apply suggestions from code review
Co-authored-by: James Ide <ide@users.noreply.github.com>
2024-02-18 10:34:08 -06:00
e9442e9457 Update to newest adafruit_httpserver; make content dynamic
Now it'll name the specific device and version in the returned
(text/plain) content.
2024-02-16 10:04:38 -06:00
2c7939bb06 Use circup to install adafruit_httpserver
The bundled httpserver was old and its mpy format was not
compatible with circuitpython 9
2024-02-16 10:04:14 -06:00
13 changed files with 22 additions and 8 deletions

1
circup_requirements.txt Normal file
View file

@ -0,0 +1 @@
adafruit_requests==2.0.5

View file

@ -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'

View file

@ -7,7 +7,17 @@ import socketpool
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:
@ -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
@ -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:")

View file

@ -1,3 +0,0 @@
<!DOCTYPE html>
<title>Hello world &middot; Raspberry Pi Pico W</title>
<p>Hello world from Raspberry Pi Pico W!</p>