Skip to content

Commit 09c3fe4

Browse files
committed
add temperature example
1 parent f5c3d5d commit 09c3fe4

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Uncomment the below if you use native CircuitPython modules such as
2626
# digitalio, micropython and busio. List the modules you use. Without it, the
2727
# autodoc module docs will fail to generate with a warning.
28-
# autodoc_mock_imports = ["digitalio", "busio"]
28+
autodoc_mock_imports = ["microcontroller"]
2929

3030

3131
intersphinx_mapping = {

examples/httpserver_temperature.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SPDX-FileCopyrightText: 2022 Dan Halbert for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
from secrets import secrets # pylint: disable=no-name-in-module
6+
7+
import microcontroller
8+
import socketpool
9+
import wifi
10+
11+
from adafruit_httpserver import HTTPServer, HTTPResponse
12+
13+
ssid = secrets["ssid"]
14+
print("Connecting to", ssid)
15+
wifi.radio.connect(ssid, secrets["password"])
16+
print("Connected to", ssid)
17+
print(f"Listening on http://{wifi.radio.ipv4_address}:80")
18+
19+
pool = socketpool.SocketPool(wifi.radio)
20+
server = HTTPServer(pool)
21+
22+
23+
@server.route("/temperature")
24+
def base(request): # pylint: disable=unused-argument
25+
"""Return the current temperature"""
26+
# pylint: disable=no-member
27+
return HTTPResponse(body=f"{str(microcontroller.cpu.temperature)}")
28+
29+
30+
# Never returns
31+
server.serve_forever(str(wifi.radio.ipv4_address))

0 commit comments

Comments
 (0)