Skip to content

Make WiFi enabled settable and add temperature logger example #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)