-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensor_read.py
35 lines (30 loc) · 957 Bytes
/
sensor_read.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
25
26
27
28
29
30
31
32
33
34
35
import subprocess
import time
import RPi.GPIO as GPIO
import bme280
def readTempI2C():
try:
res = subprocess.run(["cat","/sys/bus/w1/devices/28-0417822adbff/temperature"],stdout=subprocess.PIPE)
tmpstr = res.stdout.decode('utf-8')
tmp = float(tmpstr)
return tmp/1000.0
except:
print("error while reading tmp!")
return 0.0
def readBME280():
try:
temperature,pressure,humidity = bme280.readBME280All()
return (temperature,pressure,humidity)
except:
print("error reading bme280")
return (0,0,0)
def getWeatherInfo():
temperature,pressure,humidity = readBME280()
return {"temperature":readTempI2C(),"temperature2":temperature,
"humidity":humidity,"pressure":pressure}
if __name__ == "__main__":
while True:
for k,v in getWeatherInfo():
print(k," = ",v)
print("-------------------")
time.sleep(1)