Skip to content

Commit 3aef113

Browse files
committed
Add a bare minimum simpletest example
1 parent 0850aba commit 3aef113

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

examples/httpserver_simpletest.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-FileCopyrightText: 2023 JR Rickerson for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
import os
6+
7+
import socketpool
8+
import wifi
9+
10+
from adafruit_httpserver.mime_type import MIMEType
11+
from adafruit_httpserver.request import HTTPRequest
12+
from adafruit_httpserver.response import HTTPResponse
13+
from adafruit_httpserver.server import HTTPServer
14+
15+
16+
ssid = os.getenv("WIFI_SSID")
17+
password = os.getenv("WIFI_PASSWORD")
18+
19+
print("Connecting to", ssid)
20+
wifi.radio.connect(ssid, password)
21+
print("Connected to", ssid)
22+
23+
pool = socketpool.SocketPool(wifi.radio)
24+
server = HTTPServer(pool, "")
25+
26+
27+
@server.route("/")
28+
def base(request: HTTPRequest):
29+
"""
30+
Serve a static text response to ensure the server is running.
31+
"""
32+
with HTTPResponse(request, content_type=MIMEType.TYPE_TXT) as response:
33+
message = "Hello from the CircuitPython HTTPServer!"
34+
response.send(message)
35+
36+
37+
print(f"Listening on http://{wifi.radio.ipv4_address}:80")
38+
server.serve_forever(str(wifi.radio.ipv4_address))

0 commit comments

Comments
 (0)