Merge pull request #32 from senaduka/fix_w1_thermo_readings
- added boundaries while reading w1 thermo sensor (-30 to +60 C)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
|
||||
import re
|
||||
import datetime
|
||||
import time
|
||||
|
||||
def read_one_thermo(filename):
|
||||
try:
|
||||
@@ -15,11 +16,26 @@ def read_one_thermo(filename):
|
||||
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
|
||||
# with open("/mnt/zoblakdata/w1_sensor_log_sent","a") as log:
|
||||
# log.write(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + ' | filename: ' + filename + ' | reading: ' + str(x+1) + '\n' )
|
||||
# log.write(filetext)
|
||||
# log.write("--------\n")
|
||||
result = (int(first_part) + (int(second_part) / (10.0 ** NO_OF_DECIMALS) )) * sign
|
||||
if result >= -30.0 and result <= 60.0:
|
||||
return result
|
||||
# if x == 2:
|
||||
# with open("/mnt/zoblakdata/w1_sensor_log_probable_exception","a") as log2:
|
||||
# log2.write(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + ' | filename: ' + filename + ' | reading: ' + str(x+1) + '\n' )
|
||||
# log2.write(filetext)
|
||||
# log2.write("--------\n")
|
||||
time.sleep(5)
|
||||
print 'error'
|
||||
print e
|
||||
return -101.0
|
||||
except Exception as e:
|
||||
# with open("/mnt/zoblakdata/w1_sensor_log_exception","a") as log3:
|
||||
# log3.write(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + ' - exception!\n')
|
||||
# log3.write("--------\n")
|
||||
print 'errror'
|
||||
print e
|
||||
return -100.0
|
||||
|
||||
Reference in New Issue
Block a user