Skip to content

Instantly share code, notes, and snippets.

@elizabethn119
Last active November 14, 2019 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elizabethn119/33c4837290c6d5d21ca9359c90d014f4 to your computer and use it in GitHub Desktop.
Save elizabethn119/33c4837290c6d5d21ca9359c90d014f4 to your computer and use it in GitHub Desktop.
import time
import board
import busio
import adafruit_bme280
from ISStreamer.Streamer import Streamer
# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
# --------- User Settings ---------
SENSOR_LOCATION_NAME = "Office"
BUCKET_NAME = ":partly_sunny: Room Temperature"
BUCKET_KEY = "temp1"
ACCESS_KEY = "YOUR ACCESS KEY HERE"
# change this to match the location's pressure (hPa) at sea level
bme280.sea_level_pressure = 1013.25
MINUTES_BETWEEN_READS = 10
METRIC_UNITS = False
# ---------------------------------
# OR create library object using our Bus SPI port
#spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
#bme_cs = digitalio.DigitalInOut(board.D10)
#bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs)
streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)
while True:
humidity = format(bme280.humidity, ".1f")
pressure = format(bme280.pressure, ".1f")
temp_c = bme280.temperature
if METRIC_UNITS:
streamer.log(SENSOR_LOCATION_NAME + "Temperature(C)", temp_c)
else:
temp_f = format(temp_c * 9.0 / 5.0 + 32.0, ".1f")
streamer.log(SENSOR_LOCATION_NAME + " Temperature(F)", temp_f)
streamer.log(SENSOR_LOCATION_NAME + "Humidity(%)", humidity)
streamer.log(SENSOR_LOCATION_NAME + "Pressure(hPA)", pressure)
streamer.flush()
time.sleep(60*MINUTES_BETWEEN_READS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment