-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththermo.py
More file actions
executable file
·50 lines (34 loc) · 975 Bytes
/
thermo.py
File metadata and controls
executable file
·50 lines (34 loc) · 975 Bytes
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python
import os
import time
import sys
import datetime
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
temp_sensor = '/sys/bus/w1/devices/<serial>/w1_slave'
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
temp_f = temp_c * 9.0 / 5.0 + 32.0
return temp_f
print(st + "," + str(read_temp()))
# Uncomment to print just the temperature
# while True:
# print(read_temp(0))
# time.sleep(1)
# Uncomment to print timestamp,temp
# if True:
# print(st + "," + str(read_temp()))