Skip to content

Commit 69acd0b

Browse files
authored
Merge pull request #12 from makermelissa/main
Make WiFi enabled settable and add temperature logger example
2 parents 4d4da6d + a95a79c commit 69acd0b

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

adafruit_funhouse/network.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,11 @@ def on_mqtt_message(self, value):
216216
@property
217217
def enabled(self):
218218
"""
219-
Return whether the WiFi is enabled
219+
Get or Set whether the WiFi is enabled
220220
221221
"""
222222
return self._wifi.enabled
223+
224+
@enabled.setter
225+
def enabled(self, value):
226+
self._wifi.enabled = bool(value)

docs/examples.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ MQTT Example
1313
.. literalinclude:: ../examples/funhouse_adafruit_io_mqtt.py
1414
:caption: examples/funhouse_adafruit_io_mqtt.py
1515
:linenos:
16+
17+
Temperature Logger Example
18+
---------------------------
19+
20+
.. literalinclude:: ../examples/funhouse_temperature_logger.py
21+
:caption: examples/funhouse_temperature_logger.py
22+
:linenos:
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2+
# SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries
3+
#
4+
# SPDX-License-Identifier: MIT
5+
"""
6+
This example demonstrates how to log temperature on the FunHouse. Due to the sensors being near the
7+
power supply, usage of peripherals generates extra heat. By turning off unused peripherals and back
8+
on only during usage, it can lower the heat. Using light sleep in between readings will also help.
9+
By using an offset, we can improve the accuracy even more. Improving airflow near the FunHouse will
10+
also help.
11+
"""
12+
13+
from adafruit_funhouse import FunHouse
14+
15+
funhouse = FunHouse(default_bg=None)
16+
17+
DELAY = 180
18+
FEED = "temperature"
19+
TEMPERATURE_OFFSET = (
20+
3 # Degrees C to adjust the temperature to compensate for board produced heat
21+
)
22+
23+
# Turn things off
24+
funhouse.peripherals.dotstars.fill(0)
25+
funhouse.display.brightness = 0
26+
funhouse.network.enabled = False
27+
28+
29+
def log_data():
30+
print("Logging Temperature")
31+
print("Temperature %0.1F" % (funhouse.peripherals.temperature - TEMPERATURE_OFFSET))
32+
# Turn on WiFi
33+
funhouse.network.enabled = True
34+
# Connect to WiFi
35+
funhouse.network.connect()
36+
# Push to IO using REST
37+
funhouse.push_to_io(FEED, funhouse.peripherals.temperature - TEMPERATURE_OFFSET)
38+
# Turn off WiFi
39+
funhouse.network.enabled = False
40+
41+
42+
while True:
43+
log_data()
44+
print("Sleeping for {} seconds...".format(DELAY))
45+
funhouse.enter_light_sleep(DELAY)

0 commit comments

Comments
 (0)