forked from Honey-Pi/rpi-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_bme280.py
24 lines (20 loc) · 1.11 KB
/
read_bme280.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python
# This file is part of HoneyPi [honey-pi.de] which is released under Creative Commons License Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0).
# See file LICENSE or go to http://creativecommons.org/licenses/by-nc-sa/3.0/ for full license details.
import time
from sensors.bme280 import readBME280All #http://bit.ly/bme280py
def measure_bme280(ts_sensor):
fields = {}
try:
temperature,pressure,humidity = readBME280All()
# ThingSpeak fields
# Create returned dict if ts-field is defined
if 'ts_field_temperature' in ts_sensor and isinstance(temperature, (int, float)):
fields[ts_sensor["ts_field_temperature"]] = round(temperature, 2)
if 'ts_field_humidity' in ts_sensor and isinstance(humidity, (int, float)):
fields[ts_sensor["ts_field_humidity"]] = round(humidity, 2)
if 'ts_field_air_pressure' in ts_sensor and isinstance(pressure, (int, float)):
fields[ts_sensor["ts_field_air_pressure"]] = round(pressure, 2)
except OSError:
print('No BME280 Sensor connected.')
return fields