forked from cymplecy/scratch_gpio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
temptest2.py
executable file
·39 lines (33 loc) · 1.32 KB
/
temptest2.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
#!/usr/bin/env python
import time
import os
os.system('sudo modprobe w1-gpio')
os.system('sudo modprobe w1-therm')
possSensors = os.listdir('/sys/bus/w1/devices')
#print possSensors
dsSensorId = "28"
for loop in possSensors:
if loop[:2] == "28":
dsSensorId = loop
temperatures = []
for polltime in range(0,5):
tfile = open("/sys/bus/w1/devices/"+ dsSensorId +"/w1_slave")
# Read all of the text in the file.
text = tfile.read()
# Close the file now that the text has been read.
tfile.close()
# Split the text with new lines (\n) and select the second line.
secondline = text.split("\n")[1]
# Split the line into words, referring to the spaces, and select the 10th word (counting from 0).
temperaturedata = secondline.split(" ")[9]
# The first two characters are "t=", so get rid of those and convert the temperature from a string to a number.
temperature = float(temperaturedata[2:]) / 1000.0
# Put the decimal point in the right place and display it.
temperatures.append(temperature )
print temperature
# time.sleep(1)
temperatures = sorted(temperatures)
#del temperatures[6]
#del temperatures[0]
avgtemperature =(sum(temperatures) / float(len(temperatures)))
print "average" , avgtemperature