This commit is contained in:
phm3
2019-02-01 15:00:51 +00:00
commit d44c021767
8 changed files with 1508 additions and 0 deletions

36
UI/bdsensors.py Normal file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/env python
import os
import glob
import time
import subprocess
# this needs to be automated later TODO
base_dir = '/sys/bus/w1/devices/'
# here is the prefix of the hardware in this case, 10
device_folder = glob.glob(base_dir + '00*')[0]
device_file = device_folder + '/w1_bus_master1'
def read_temp_raw(): # This function reads the raw sensor chip information
catdata = subprocess.Popen(
['cat', device_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = catdata.communicate()
out_decode = out.decode('utf-8')
lines = out_decode.split('\n')
return lines
def read_temp(): # This function takes the the raw sensor chip information
lines = read_temp_raw() # strips it down and takes only the temperature out
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = read_temp_raw()
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
# Calculates temperature in celcius and stores it in variable
temp_c = float(temp_string) / 1000.0
# Calculates temperature in fahreint and stores it in variable
temp_f = temp_c * 9.0 / 5.0 + 32.0
return temp_c # here it returns only the temperature in celcius