Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 'thermcron.sh'
- # thermo cron job script
- #!/bin/sh
- python /root/thermo.py >> /root/hulk_log.csv
- # 'thermo.py'
- # script to get temp, convert to fahrenheit.
- # output is '2015-12-20 17:04:02,83.75'
- import os
- import time
- import sys
- import datetime
- os.system('modprobe w1-gpio')
- os.system('modprobe w1-therm')
- temp_sensor='/sys/bus/w1/devices/28-000006c83b77/w1_slave' # replace 28-000006c83b77 with serial of your DS18b20 temp sensor
- ts = time.time()
- st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
- def temp_raw():
- f = open(temp_sensor, 'r')
- lines = f.readlines()
- f.close()
- return lines
- def read_temp():
- lines = temp_raw()
- while lines[0].strip()[-3:] != 'YES':
- time.sleep(0.2)
- lines = temp_raw()
- temp_output = lines[1].find('t=')
- if temp_output != -1:
- temp_string = lines[1].strip()[temp_output+2:]
- temp_c = float(temp_string) / 1000.0 # defines temp in celcius, in xx.xxxx format
- temp_f = temp_c * 9.0 / 5.0 + 32.0 # defines temp in fahrenheit, with respect to temp_c
- return temp_f
- #while True:
- # print(read_temp()) ; print(ts)
- # time.sleep(1)
- #sys.exit(0)
- if True:
- print(st + "," + str(read_temp())) #output is 2015-12-20 17:04:02,83.75
Add Comment
Please, Sign In to add comment