-100 for nonexistent sensor

This commit is contained in:
Senad Uka
2016-10-29 18:02:04 +02:00
parent f93f1cbe13
commit fd590daecf
2 changed files with 18 additions and 13 deletions

View File

@@ -1,20 +1,25 @@
import re
def read_one_thermo(filename):
NO_OF_DECIMALS = 3
textfile = open(filename, 'r')
filetext = textfile.read()
textfile.close()
try:
NO_OF_DECIMALS = 3
textfile = open(filename, 'r')
filetext = textfile.read()
textfile.close()
matches = re.findall("t=(\-?)(\d+)", filetext)
sign = -1 if matches[0][0] == '-' else 1
whole_reading = matches[0][1]
first_part = matches[0][1][0:-NO_OF_DECIMALS]
second_part = matches[0][1][-NO_OF_DECIMALS:]
first_part = '0' if first_part == '' else first_part
return (int(first_part) + (int(second_part) / (10.0 ** NO_OF_DECIMALS) )) * sign
matches = re.findall("t=(\-?)(\d+)", filetext)
sign = -1 if matches[0][0] == '-' else 1
whole_reading = matches[0][1]
first_part = matches[0][1][0:-NO_OF_DECIMALS]
second_part = matches[0][1][-NO_OF_DECIMALS:]
first_part = '0' if first_part == '' else first_part
return (int(first_part) + (int(second_part) / (10.0 ** NO_OF_DECIMALS) )) * sign
except Exception as e:
print 'errror'
print e
return -100.0
def read_many_thermo(filenames):
result = []
for filename in list(filenames):