Skip to content

Commit

Permalink
Merge pull request #12 from makermelissa/main
Browse files Browse the repository at this point in the history
Make WiFi enabled settable and add temperature logger example
  • Loading branch information
makermelissa authored Apr 28, 2021
2 parents 4d4da6d + a95a79c commit 69acd0b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
6 changes: 5 additions & 1 deletion adafruit_funhouse/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ def on_mqtt_message(self, value):
@property
def enabled(self):
"""
Return whether the WiFi is enabled
Get or Set whether the WiFi is enabled
"""
return self._wifi.enabled

@enabled.setter
def enabled(self, value):
self._wifi.enabled = bool(value)
7 changes: 7 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ MQTT Example
.. literalinclude:: ../examples/funhouse_adafruit_io_mqtt.py
:caption: examples/funhouse_adafruit_io_mqtt.py
:linenos:

Temperature Logger Example
---------------------------

.. literalinclude:: ../examples/funhouse_temperature_logger.py
:caption: examples/funhouse_temperature_logger.py
:linenos:
45 changes: 45 additions & 0 deletions examples/funhouse_temperature_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
This example demonstrates how to log temperature on the FunHouse. Due to the sensors being near the
power supply, usage of peripherals generates extra heat. By turning off unused peripherals and back
on only during usage, it can lower the heat. Using light sleep in between readings will also help.
By using an offset, we can improve the accuracy even more. Improving airflow near the FunHouse will
also help.
"""

from adafruit_funhouse import FunHouse

funhouse = FunHouse(default_bg=None)

DELAY = 180
FEED = "temperature"
TEMPERATURE_OFFSET = (
3 # Degrees C to adjust the temperature to compensate for board produced heat
)

# Turn things off
funhouse.peripherals.dotstars.fill(0)
funhouse.display.brightness = 0
funhouse.network.enabled = False


def log_data():
print("Logging Temperature")
print("Temperature %0.1F" % (funhouse.peripherals.temperature - TEMPERATURE_OFFSET))
# Turn on WiFi
funhouse.network.enabled = True
# Connect to WiFi
funhouse.network.connect()
# Push to IO using REST
funhouse.push_to_io(FEED, funhouse.peripherals.temperature - TEMPERATURE_OFFSET)
# Turn off WiFi
funhouse.network.enabled = False


while True:
log_data()
print("Sleeping for {} seconds...".format(DELAY))
funhouse.enter_light_sleep(DELAY)

0 comments on commit 69acd0b

Please sign in to comment.