Skip to content

Instantly share code, notes, and snippets.

@jrbail01
Last active July 13, 2020 12:45
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/1ed96ccb2bee7649194013b0a1f03be9 to your computer and use it in GitHub Desktop.
Save jrbail01/1ed96ccb2bee7649194013b0a1f03be9 to your computer and use it in GitHub Desktop.
import time
import smbus2
import bme280
import psutil
from ISStreamer.Streamer import Streamer
from subprocess import PIPE, Popen
# --------- User Settings ---------
SENSOR_LOCATION_NAME = "crawl2"
BUCKET_NAME = ":partly_sunny: Room Temperature"
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)
process = Popen(['hostname', '-I'], stdout=PIPE)
output, _error = process.communicate()
streamer.log("Crawl2 Temperature Monitor IP Address", output.rstrip())
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