From 2f1c484c7b2be571cc798008bf71eb83b3d32a88 Mon Sep 17 00:00:00 2001 From: DJDevon3 <49322231+DJDevon3@users.noreply.github.com> Date: Tue, 26 Mar 2024 23:50:47 -0400 Subject: [PATCH 1/2] Add httpserver simpletest with connection manager Only handles setup for socketpool. Coming from requests examples I'm more used to seeing connection manager handle the pool now. It might be good for consistency to role out connection manager for all examples but I'll leave that up to you. --- ...httpserver_simpletest_connectionmanager.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 examples/httpserver_simpletest_connectionmanager.py diff --git a/examples/httpserver_simpletest_connectionmanager.py b/examples/httpserver_simpletest_connectionmanager.py new file mode 100644 index 0000000..80a21cb --- /dev/null +++ b/examples/httpserver_simpletest_connectionmanager.py @@ -0,0 +1,34 @@ +# SPDX-FileCopyrightText: 2024 DJDevon3 +# SPDX-License-Identifier: MIT +# Coded for Circuit Python 9. +"""HTTP Server Simpletest with Connection Manager""" +# pylint: disable=import-error + +import os + +import adafruit_connection_manager +import wifi + +from adafruit_httpserver import Server, Request, Response + +# Get WiFi details, ensure these are setup in settings.toml +ssid = os.getenv("CIRCUITPY_WIFI_SSID") +password = os.getenv("CIRCUITPY_WIFI_PASSWORD") + +print("Connecting to WiFi...") +wifi.radio.connect(ssid, password) +print("✅ Wifi!") + +# Initalize Wifi, Socket Pool, Request Session +pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) +ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) +server = Server(pool, "/static", debug=True) + + +@server.route("/") +def base(request: Request): + """Serve a default static plain text message""" + return Response(request, "Hello from the CircuitPython HTTP Server!") + + +server.serve_forever(str(wifi.radio.ipv4_address)) From 863ac1e73cda555a9edef966c57ecdbad5b1c079 Mon Sep 17 00:00:00 2001 From: DJDevon3 <49322231+DJDevon3@users.noreply.github.com> Date: Wed, 27 Mar 2024 21:10:37 -0400 Subject: [PATCH 2/2] removed unused ssl_context Changed ssid and password env's to match the simpletest_manual example. --- examples/httpserver_simpletest_connectionmanager.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/httpserver_simpletest_connectionmanager.py b/examples/httpserver_simpletest_connectionmanager.py index 80a21cb..ff44d23 100644 --- a/examples/httpserver_simpletest_connectionmanager.py +++ b/examples/httpserver_simpletest_connectionmanager.py @@ -12,8 +12,8 @@ from adafruit_httpserver import Server, Request, Response # Get WiFi details, ensure these are setup in settings.toml -ssid = os.getenv("CIRCUITPY_WIFI_SSID") -password = os.getenv("CIRCUITPY_WIFI_PASSWORD") +ssid = os.getenv("WIFI_SSID") +password = os.getenv("WIFI_PASSWORD") print("Connecting to WiFi...") wifi.radio.connect(ssid, password) @@ -21,7 +21,6 @@ # Initalize Wifi, Socket Pool, Request Session pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) -ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio) server = Server(pool, "/static", debug=True)