Last active
July 13, 2020 12:45
-
-
Save jrbail01/1ed96ccb2bee7649194013b0a1f03be9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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