From 493faad7c77377010fe8af7a2afa437f0df1276b Mon Sep 17 00:00:00 2001 From: EddieSneed Date: Sun, 14 Jun 2020 22:42:01 -0400 Subject: [PATCH 1/7] Create adafruit_io.py I wanted to create a script to allow both the OLED display scripts to run and provide an awesome local display, while at the same time sending the data to your AIO dashboard. --- examples/adafruit_io.py | 118 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 examples/adafruit_io.py diff --git a/examples/adafruit_io.py b/examples/adafruit_io.py new file mode 100644 index 0000000..f95a4e3 --- /dev/null +++ b/examples/adafruit_io.py @@ -0,0 +1,118 @@ +""" +This code comes directly from Adafruit's learning guide on building an environmental monitor +either with a Raspberry Pi, or Feather. I wanted to see if I could use it, minus a few bits and bobs, +to regularly send enviro-data using my Pimoroni Enviro+ Pi-HAT to my AIO dashboard all while running another +python program provided by Pimoroni to display all the values nicely on it's OLED display. + +I kept having conflicts every time I tried to incorporate AIO into their code, so I decided to use this base code +along side it to resolve the conflicts. Just add both the 'weather-and-light.py' and this file to your /etc/rc.local +boot file, and you will be able to see the values both locally as well as your Adafruit IO dashboard! + + ~dedSyn4ps3 + +""" + +""" +'environmental_monitor.py' +=============================================================================== +Example of sending I2C sensor data +from multiple sensors to Adafruit IO. + +Tutorial Link: https://learn.adafruit.com/adafruit-io-air-quality-monitor + +Adafruit invests time and resources providing this open source code. +Please support Adafruit and open source hardware by purchasing +products from Adafruit! + +Author(s): Brent Rubell for Adafruit Industries +Copyright (c) 2018 Adafruit Industries +Licensed under the MIT license. +All text above must be included in any redistribution. + +Dependencies: + - Adafruit_Blinka (CircuitPython, on Pi.) + (https://github.com/adafruit/Adafruit_Blinka) + + - Adafruit_CircuitPython_BME280. + (https://github.com/adafruit/Adafruit_CircuitPython_BME280) +""" + + +#!/usr/bin/env python3 + +# Import standard python modules +import time + +# import Adafruit Blinka +import board +import busio + +# import sensor libraries +import adafruit_sgp30 +import adafruit_veml6070 +import adafruit_bme280 + +# import Adafruit IO REST client +from Adafruit_IO import Client, Feed, RequestError + +# Set to your Adafruit IO key. +# Remember, your key is a secret, +# so make sure not to publish it when you publish this code! +ADAFRUIT_IO_KEY = 'YOUR_AIO_KEY' + +# Set to your Adafruit IO username. +# (go to https://accounts.adafruit.com to find your username) +ADAFRUIT_IO_USERNAME = 'YOUR_AIO_USERNAME' + +# Create an instance of the REST client +aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY) + +try: # if we already have the feeds, assign them. + + temperature_feed = aio.feeds('temperature') + humidity_feed = aio.feeds('humidity') + pressure_feed = aio.feeds('pressure') + altitude_feed = aio.feeds('altitude') + +except RequestError: # if we don't, create and assign them. + + temperature_feed = aio.create_feed(Feed(name='temperature')) + humidity_feed = aio.create_feed(Feed(name='humidity')) + pressure_feed = aio.create_feed(Feed(name='pressure')) + altitude_feed = aio.create_feed(Feed(name='altitude')) + +# Create busio I2C +i2c = busio.I2C(board.SCL, board.SDA, frequency=100000) + +# Create BME280 object. +bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) +bme280.sea_level_pressure = 1013.25 + + +while True: + + try: + + # Read BME280 + temp_data = bme280.temperature + temp_data = int(temp_data) * 1.8 + 22 #The 22 is just a slight correction to offset heat dissipation from the pi's hardware + humid_data = bme280.humidity + pressure_data = bme280.pressure + alt_data = bme280.altitude + + # Send BME280 Data + + aio.send(temperature_feed.key, temp_data) + aio.send(humidity_feed.key, int(humid_data)) + + time.sleep(2) + + aio.send(pressure_feed.key, int(pressure_data)) + aio.send(altitude_feed.key, int(alt_data)) + + # Avoid timeout from aio + time.sleep(30) + + except Exception: + + break \ No newline at end of file From dead119b25cf4a42a071aaee9e97ea34a882ab8a Mon Sep 17 00:00:00 2001 From: EddieSneed Date: Mon, 15 Jun 2020 00:27:58 -0400 Subject: [PATCH 2/7] Update adafruit_io.py Forgot to add specific address for bme280. Removed sensor imports that aren't used. --- examples/adafruit_io.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/examples/adafruit_io.py b/examples/adafruit_io.py index f95a4e3..c04f4b7 100644 --- a/examples/adafruit_io.py +++ b/examples/adafruit_io.py @@ -46,10 +46,6 @@ # import Adafruit Blinka import board import busio - -# import sensor libraries -import adafruit_sgp30 -import adafruit_veml6070 import adafruit_bme280 # import Adafruit IO REST client @@ -82,10 +78,10 @@ altitude_feed = aio.create_feed(Feed(name='altitude')) # Create busio I2C -i2c = busio.I2C(board.SCL, board.SDA, frequency=100000) +i2c = busio.I2C(board.SCL, board.SDA) # Create BME280 object. -bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) +bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) bme280.sea_level_pressure = 1013.25 From e84e8abac6feff27ae10e30cccd7a28bc690efd7 Mon Sep 17 00:00:00 2001 From: EddieSneed <49820403+dedSyn4ps3@users.noreply.github.com> Date: Mon, 15 Jun 2020 14:18:00 -0400 Subject: [PATCH 3/7] Update adafruit_io.py Added a few comments for clarification. --- examples/adafruit_io.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/examples/adafruit_io.py b/examples/adafruit_io.py index c04f4b7..25eb09e 100644 --- a/examples/adafruit_io.py +++ b/examples/adafruit_io.py @@ -5,8 +5,9 @@ python program provided by Pimoroni to display all the values nicely on it's OLED display. I kept having conflicts every time I tried to incorporate AIO into their code, so I decided to use this base code -along side it to resolve the conflicts. Just add both the 'weather-and-light.py' and this file to your /etc/rc.local -boot file, and you will be able to see the values both locally as well as your Adafruit IO dashboard! +along side it to resolve the conflicts. Just add both this file to your /etc/rc.local +boot file, along with whatever oled display code from the examples folder (I prefer the temperature-and-light), and +you will be able to see the values both locally as well as your Adafruit IO dashboard! ~dedSyn4ps3 @@ -63,14 +64,14 @@ # Create an instance of the REST client aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY) -try: # if we already have the feeds, assign them. +try: # Assign feeds if they already exist temperature_feed = aio.feeds('temperature') humidity_feed = aio.feeds('humidity') pressure_feed = aio.feeds('pressure') altitude_feed = aio.feeds('altitude') -except RequestError: # if we don't, create and assign them. +except RequestError: # In case they don't exist temperature_feed = aio.create_feed(Feed(name='temperature')) humidity_feed = aio.create_feed(Feed(name='humidity')) @@ -78,11 +79,11 @@ altitude_feed = aio.create_feed(Feed(name='altitude')) # Create busio I2C -i2c = busio.I2C(board.SCL, board.SDA) +i2c = busio.I2C(board.SCL, board.SDA) # Removed baudrate declaration, if needed, assign rate appropriate for your device(s) -# Create BME280 object. -bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) -bme280.sea_level_pressure = 1013.25 +# Create BME280 object +bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) # Original Adafruit example did not explicitly state the address of the sensor, which is needed to properly function +bme280.sea_level_pressure = 1023.50 # Sea level pressure here in Ohio while True: @@ -111,4 +112,4 @@ except Exception: - break \ No newline at end of file + break From c9b9ec74023a7d0be402ab1e9446852ac3f6e321 Mon Sep 17 00:00:00 2001 From: EddieSneed <49820403+dedSyn4ps3@users.noreply.github.com> Date: Wed, 17 Jun 2020 14:37:23 -0400 Subject: [PATCH 4/7] Update weather-and-light.py Updated city name and time zone for my location --- examples/weather-and-light.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/weather-and-light.py b/examples/weather-and-light.py index bccf7cc..76ce10d 100755 --- a/examples/weather-and-light.py +++ b/examples/weather-and-light.py @@ -303,8 +303,8 @@ def describe_light(light): HEIGHT = disp.height # The city and timezone that you want to display. -city_name = "Sheffield" -time_zone = "Europe/London" +city_name = "Columbus" +time_zone = "US/New_York" # Values that alter the look of the background blur = 50 From 29ced5f1e09fe29e8af530c4e854d9f15d3e16cb Mon Sep 17 00:00:00 2001 From: EddieSneed <49820403+dedSyn4ps3@users.noreply.github.com> Date: Wed, 17 Jun 2020 14:45:34 -0400 Subject: [PATCH 5/7] Update weather-and-light.py Updated proper time zone definition & Centigrade -> Fahrenheit conversion --- examples/weather-and-light.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/weather-and-light.py b/examples/weather-and-light.py index 76ce10d..00ec7b9 100755 --- a/examples/weather-and-light.py +++ b/examples/weather-and-light.py @@ -304,7 +304,7 @@ def describe_light(light): # The city and timezone that you want to display. city_name = "Columbus" -time_zone = "US/New_York" +time_zone = "US/Eastern" # Values that alter the look of the background blur = 50 @@ -366,6 +366,7 @@ def describe_light(light): cpu_temps = cpu_temps[1:] + [cpu_temp] avg_cpu_temp = sum(cpu_temps) / float(len(cpu_temps)) corr_temperature = temperature - ((avg_cpu_temp - temperature) / factor) + corr_temperature_f = corr_temperature * 1.8 + 32 if time_elapsed > 30: if min_temp is not None and max_temp is not None: @@ -377,7 +378,7 @@ def describe_light(light): min_temp = corr_temperature max_temp = corr_temperature - temp_string = f"{corr_temperature:.0f}°C" + temp_string = f"{corr_temperature_f:.0f}°F" img = overlay_text(img, (68, 18), temp_string, font_lg, align_right=True) spacing = font_lg.getsize(temp_string)[1] + 1 if min_temp is not None and max_temp is not None: From b47ea664545029e7be880e97240cec1c1dcc19f8 Mon Sep 17 00:00:00 2001 From: EddieSneed <49820403+dedSyn4ps3@users.noreply.github.com> Date: Wed, 17 Jun 2020 14:49:46 -0400 Subject: [PATCH 6/7] Update weather-and-light.py min_temp & max_temp changed to reflect corr_temp_f... --- examples/weather-and-light.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/weather-and-light.py b/examples/weather-and-light.py index 00ec7b9..1f9676c 100755 --- a/examples/weather-and-light.py +++ b/examples/weather-and-light.py @@ -371,12 +371,12 @@ def describe_light(light): if time_elapsed > 30: if min_temp is not None and max_temp is not None: if corr_temperature < min_temp: - min_temp = corr_temperature + min_temp = corr_temperature_f elif corr_temperature > max_temp: - max_temp = corr_temperature + max_temp = corr_temperature_f else: - min_temp = corr_temperature - max_temp = corr_temperature + min_temp = corr_temperature_f + max_temp = corr_temperature_f temp_string = f"{corr_temperature_f:.0f}°F" img = overlay_text(img, (68, 18), temp_string, font_lg, align_right=True) From dd22b0015eb35f871ca9eff201dc665e682bd7d4 Mon Sep 17 00:00:00 2001 From: Ed Rutherford Date: Sat, 23 Jul 2022 23:18:34 -0400 Subject: [PATCH 7/7] Revert Original Merge - Remove old merge request code - Add new contribution links for additional projects --- README.md | 3 +- examples/adafruit_io.py | 115 ---------------------------------- examples/weather-and-light.py | 15 +++-- 3 files changed, 9 insertions(+), 124 deletions(-) delete mode 100644 examples/adafruit_io.py diff --git a/README.md b/README.md index 2314c81..24e4a78 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,10 @@ sudo apt install python3-numpy python3-smbus python3-pil python3-setuptools ## Alternate Software & User Projects +* Enviro Plus Dashboard - https://gitlab.com/dedSyn4ps3/enviroplus-dashboard - A React-based web dashboard for viewing sensor data +* Enviro+ Example Projects - https://gitlab.com/dedSyn4ps3/enviroplus-python-projects - Includes original examples plus code to stream to Adafruit IO (more projects coming soon) * enviro monitor - https://github.com/roscoe81/enviro-monitor * mqtt-all - https://github.com/robmarkcole/rpi-enviro-mqtt - now upstream: [see examples/mqtt-all.py](examples/mqtt-all.py) -* adafruit_io.py - https://github.com/dedSyn4ps3/enviroplus-python/blob/master/examples/adafruit_io.py - uses Adafruit Blinka and BME280 libraries to publish to Adafruit IO * enviroplus_exporter - https://github.com/tijmenvandenbrink/enviroplus_exporter - Prometheus exporter (with added support for Luftdaten and InfluxDB Cloud) * homekit-enviroplus - https://github.com/sighmon/homekit-enviroplus - An Apple HomeKit accessory for the Pimoroni Enviro+ * go-enviroplus - https://github.com/rubiojr/go-enviroplus - Go modules to read Enviro+ sensors diff --git a/examples/adafruit_io.py b/examples/adafruit_io.py deleted file mode 100644 index 25eb09e..0000000 --- a/examples/adafruit_io.py +++ /dev/null @@ -1,115 +0,0 @@ -""" -This code comes directly from Adafruit's learning guide on building an environmental monitor -either with a Raspberry Pi, or Feather. I wanted to see if I could use it, minus a few bits and bobs, -to regularly send enviro-data using my Pimoroni Enviro+ Pi-HAT to my AIO dashboard all while running another -python program provided by Pimoroni to display all the values nicely on it's OLED display. - -I kept having conflicts every time I tried to incorporate AIO into their code, so I decided to use this base code -along side it to resolve the conflicts. Just add both this file to your /etc/rc.local -boot file, along with whatever oled display code from the examples folder (I prefer the temperature-and-light), and -you will be able to see the values both locally as well as your Adafruit IO dashboard! - - ~dedSyn4ps3 - -""" - -""" -'environmental_monitor.py' -=============================================================================== -Example of sending I2C sensor data -from multiple sensors to Adafruit IO. - -Tutorial Link: https://learn.adafruit.com/adafruit-io-air-quality-monitor - -Adafruit invests time and resources providing this open source code. -Please support Adafruit and open source hardware by purchasing -products from Adafruit! - -Author(s): Brent Rubell for Adafruit Industries -Copyright (c) 2018 Adafruit Industries -Licensed under the MIT license. -All text above must be included in any redistribution. - -Dependencies: - - Adafruit_Blinka (CircuitPython, on Pi.) - (https://github.com/adafruit/Adafruit_Blinka) - - - Adafruit_CircuitPython_BME280. - (https://github.com/adafruit/Adafruit_CircuitPython_BME280) -""" - - -#!/usr/bin/env python3 - -# Import standard python modules -import time - -# import Adafruit Blinka -import board -import busio -import adafruit_bme280 - -# import Adafruit IO REST client -from Adafruit_IO import Client, Feed, RequestError - -# Set to your Adafruit IO key. -# Remember, your key is a secret, -# so make sure not to publish it when you publish this code! -ADAFRUIT_IO_KEY = 'YOUR_AIO_KEY' - -# Set to your Adafruit IO username. -# (go to https://accounts.adafruit.com to find your username) -ADAFRUIT_IO_USERNAME = 'YOUR_AIO_USERNAME' - -# Create an instance of the REST client -aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY) - -try: # Assign feeds if they already exist - - temperature_feed = aio.feeds('temperature') - humidity_feed = aio.feeds('humidity') - pressure_feed = aio.feeds('pressure') - altitude_feed = aio.feeds('altitude') - -except RequestError: # In case they don't exist - - temperature_feed = aio.create_feed(Feed(name='temperature')) - humidity_feed = aio.create_feed(Feed(name='humidity')) - pressure_feed = aio.create_feed(Feed(name='pressure')) - altitude_feed = aio.create_feed(Feed(name='altitude')) - -# Create busio I2C -i2c = busio.I2C(board.SCL, board.SDA) # Removed baudrate declaration, if needed, assign rate appropriate for your device(s) - -# Create BME280 object -bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) # Original Adafruit example did not explicitly state the address of the sensor, which is needed to properly function -bme280.sea_level_pressure = 1023.50 # Sea level pressure here in Ohio - - -while True: - - try: - - # Read BME280 - temp_data = bme280.temperature - temp_data = int(temp_data) * 1.8 + 22 #The 22 is just a slight correction to offset heat dissipation from the pi's hardware - humid_data = bme280.humidity - pressure_data = bme280.pressure - alt_data = bme280.altitude - - # Send BME280 Data - - aio.send(temperature_feed.key, temp_data) - aio.send(humidity_feed.key, int(humid_data)) - - time.sleep(2) - - aio.send(pressure_feed.key, int(pressure_data)) - aio.send(altitude_feed.key, int(alt_data)) - - # Avoid timeout from aio - time.sleep(30) - - except Exception: - - break diff --git a/examples/weather-and-light.py b/examples/weather-and-light.py index 87cc0f5..cd8ae96 100755 --- a/examples/weather-and-light.py +++ b/examples/weather-and-light.py @@ -306,8 +306,8 @@ def describe_light(light): HEIGHT = disp.height # The city and timezone that you want to display. -city_name = "Columbus" -time_zone = "US/Eastern" +city_name = "Sheffield" +time_zone = "Europe/London" # Values that alter the look of the background blur = 50 @@ -369,19 +369,18 @@ def describe_light(light): cpu_temps = cpu_temps[1:] + [cpu_temp] avg_cpu_temp = sum(cpu_temps) / float(len(cpu_temps)) corr_temperature = temperature - ((avg_cpu_temp - temperature) / factor) - corr_temperature_f = corr_temperature * 1.8 + 32 if time_elapsed > 30: if min_temp is not None and max_temp is not None: if corr_temperature < min_temp: - min_temp = corr_temperature_f + min_temp = corr_temperature elif corr_temperature > max_temp: - max_temp = corr_temperature_f + max_temp = corr_temperature else: - min_temp = corr_temperature_f - max_temp = corr_temperature_f + min_temp = corr_temperature + max_temp = corr_temperature - temp_string = f"{corr_temperature_f:.0f}°F" + temp_string = f"{corr_temperature:.0f}°C" img = overlay_text(img, (68, 18), temp_string, font_lg, align_right=True) spacing = font_lg.getsize(temp_string)[1] + 1 if min_temp is not None and max_temp is not None: