Skip to content

Instantly share code, notes, and snippets.

@jrbail01
Last active July 12, 2020 17:11
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 jrbail01/6f9d0d1f55baef9ef500cdcd1c7b9b23 to your computer and use it in GitHub Desktop.
Save jrbail01/6f9d0d1f55baef9ef500cdcd1c7b9b23 to your computer and use it in GitHub Desktop.
import time
import smbus2
import bme280
from ISStreamer.Streamer import Streamer
# --------- User Settings ---------
SENSOR_LOCATION_NAME = "crawl2"
BUCKET_NAME = ":sweat_drops: Crawl Space"
BUCKET_KEY = "temphum1234"
ACCESS_KEY = "PLACE YOUR INITIAL STATE ACCESS KEY HERE"
MINUTES_BETWEEN_READS = 10
METRIC_UNITS = False
# ---------------------------------
# BME280 settings
port = 1
address = 0x76
bus = smbus2.SMBus(port)
calibration_params = bme280.load_calibration_params(bus, address)
streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)
while True:
bme280data = bme280.sample(bus, address, calibration_params)
humidity = format(bme280data.humidity, ".1f")
temp_c = bme280data.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.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