Advertisement
simplesi

Untitled

Jan 17th, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import time
  4. import os
  5.  
  6. os.system('sudo modprobe w1-gpio')
  7. os.system('sudo modprobe  w1-therm')
  8. possSensors  = os.listdir('/sys/bus/w1/devices')
  9. #print possSensors
  10. dsSensorId = "28"
  11. for loop in possSensors:
  12.     if loop[:2] == "28":
  13.         dsSensorId = loop
  14.  
  15. temperatures = []
  16.  
  17. for polltime in range(0,5):
  18.         tfile = open("/sys/bus/w1/devices/"+ dsSensorId +"/w1_slave")
  19.         # Read all of the text in the file.
  20.         text = tfile.read()
  21.         # Close the file now that the text has been read.
  22.         tfile.close()
  23.         # Split the text with new lines (\n) and select the second line.
  24.         secondline = text.split("\n")[1]
  25.         # Split the line into words, referring to the spaces, and select the 10th word (counting from 0).
  26.         temperaturedata = secondline.split(" ")[9]
  27.         # The first two characters are "t=", so get rid of those and convert the temperature from a string to a number.
  28.         temperature = float(temperaturedata[2:]) / 1000.0
  29.         # Put the decimal point in the right place and display it.
  30.        
  31.         temperatures.append(temperature )
  32.         print temperature
  33.        # time.sleep(1)
  34. temperatures = sorted(temperatures)
  35. #del temperatures[6]
  36. #del temperatures[0]
  37. avgtemperature =(sum(temperatures) / float(len(temperatures)))
  38.        
  39. print "average" , avgtemperature
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement