File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
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 ))
You can’t perform that action at this time.
0 commit comments