diff --git a/adafruit_funhouse/network.py b/adafruit_funhouse/network.py index a5bcbdd..d97100e 100755 --- a/adafruit_funhouse/network.py +++ b/adafruit_funhouse/network.py @@ -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) diff --git a/docs/examples.rst b/docs/examples.rst index baad424..9d0f8c4 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -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: diff --git a/examples/funhouse_temperature_logger.py b/examples/funhouse_temperature_logger.py new file mode 100755 index 0000000..00dee9a --- /dev/null +++ b/examples/funhouse_temperature_logger.py @@ -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)