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 2 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
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 -@2 \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the 2 do? Also prefer to use longhand notation for flags over shorthand in scripts for self-documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This improves detecting that a file is unchanged via timestamps, and speeds up rsync as a result (though it may also need --times so that the target timestamp is set to the source timestamp).

It should be -@1 or --modify-window=1, not 2. from man rsync:

       --modify-window=NUM, -@
              When comparing two timestamps, rsync treats  the  timestamps  as
              being  equal  if  they  differ by no more than the modify-window
              value.  The default is 0, which matches  just  integer  seconds.
              If  you  specify  a negative value (and the receiver is at least
              version 3.1.3) then nanoseconds will also be taken into account.
              Specifying  1  is  useful  for  copies  to/from  MS  Windows FAT
              filesystems, because FAT represents times with a 2-second  reso‐
              lution  (allowing  times  to differ from the original by up to 1
              second).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, please use --modify-window instead of -@

--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 -a
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 {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.