Skip to content

Commit

Permalink
Merge pull request #91 from DJDevon3/DJDevon3-CMSimpleTest
Browse files Browse the repository at this point in the history
Add httpserver simpletest with connection manager
  • Loading branch information
FoamyGuy authored Apr 1, 2024
2 parents dc9f83c + 863ac1e commit 4cc9503
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/httpserver_simpletest_connectionmanager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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("WIFI_SSID")
password = os.getenv("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)
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))

0 comments on commit 4cc9503

Please sign in to comment.