Skip to content

Update PicoW_CircuitPython_HTTP_Server for new adafruit_httpserver li… #2375

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 3 commits into from
Jan 14, 2023
Merged
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
15 changes: 10 additions & 5 deletions PicoW_CircuitPython_HTTP_Server/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import adafruit_imageload
from digitalio import DigitalInOut, Direction
from adafruit_httpserver.server import HTTPServer
from adafruit_httpserver.request import HTTPRequest
from adafruit_httpserver.response import HTTPResponse
from adafruit_httpserver.methods import HTTPMethod
from adafruit_httpserver.mime_type import MIMEType
from adafruit_onewire.bus import OneWireBus
from adafruit_ds18x20 import DS18X20

Expand Down Expand Up @@ -138,13 +141,14 @@ def webpage():

# route default static IP
@server.route("/")
def base(request): # pylint: disable=unused-argument
def base(request: HTTPRequest): # pylint: disable=unused-argument
# serve the HTML f string
# with content type text/html
return HTTPResponse(content_type="text/html", body=webpage())
with HTTPResponse(request, content_type=MIMEType.TYPE_HTML) as response:
response.send(f"{webpage()}")

# if a button is pressed on the site
@server.route("/", "POST")
@server.route("/", method=HTTPMethod.POST)
def buttonpress(request):
# get the raw text
raw_text = request.raw_request.decode("utf8")
Expand All @@ -162,7 +166,8 @@ def buttonpress(request):
# toggle the parrot_pin value
parrot_pin.value = not parrot_pin.value
# reload site
return HTTPResponse(content_type="text/html", body=webpage())
with HTTPResponse(request, content_type=MIMEType.TYPE_HTML) as response:
response.send(f"{webpage()}")

print("starting server..")
# startup the server
Expand Down Expand Up @@ -231,7 +236,7 @@ def buttonpress(request):
# comment/uncomment for desired units
# temp_test = str(ds18.temperature)
temp_test = str(c_to_f(ds18.temperature))
temp_text_area.text = "Temperature: %d F" % temp_test
temp_text_area.text = "Temperature: %s F" % temp_test

#if parrot is True:
if parrot_pin.value is True:
Expand Down