-
Notifications
You must be signed in to change notification settings - Fork 0
/
TempOneWire.py
executable file
·65 lines (44 loc) · 1.28 KB
/
TempOneWire.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os,time, datetime
##############################
## Functions
##############################
def get_filepaths(directory):
file_paths = [] # list to store the directories
for root,directories,files in os.walk(directory):
for directory in directories:
filepath = os.path.join(root,directory)
file_paths.append(filepath)
return file_paths
def printReadings(full_file_paths):
allList = []
i = 0
for dir in full_file_paths:
file = dir + "/w1_slave"
f = open(file, 'r')
id = getId(dir)
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%d/%m/%Y %H:%M:%S')
reading = f.read()
temp = getTemp(reading)
f.close()
values = [st,id,str(temp)]
allList.append(values)
#writeTemp(values)
#print values
return allList
def getId(dir):
result = dir.split('devices/')
return result[1]
def getTemp(text):
temp = "t="
index = text.find(temp)+2
tempc = float(text[index:])/1000.0
return tempc
def getReadings():
full_file_paths = get_filepaths("/sys/bus/w1/devices")
full_file_paths.pop(0) #this gets rid of the non sensor directory
return printReadings(full_file_paths)
#
# while(True):
#
# time.sleep(600)