Advertisement
Guest User

Untitled

a guest
Jan 21st, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.53 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import os
  4. import eeml
  5. import time
  6.  
  7. DEBUG = 1
  8. LOGGER = 1
  9.  
  10. os.system("sudo modprobe w1-gpio")
  11. os.system("sudo modprobe w1-therm")
  12.  
  13. # COSM variables. The API_KEY and FEED are specific to your COSM account and must be changed
  14. # API_KEY = '5RNOO3ShYJxYiq2V2sgSRtz3112SAKxFQjNDQmNXc0RScz0g'
  15. # FEED = 68872
  16.  
  17. # API_URL = '/v2/feeds/{feednum}.xml' .format(feednum = FEED)
  18.  
  19. def getTemp1():
  20.     # Open the temperature sensor and read it and process the result
  21.     tfile = open("/sys/bus/w1/devices/28-0000038e4fc2/w1_slave")
  22.     text = tfile.read()
  23.     tfile.close()
  24.     temperature_data1 = text.split()[-1]
  25.     temperature1 = float(temperature_data1[2:])
  26.     temperature1 = temperature1 / 1000
  27.     # Show only one decimal
  28.     temperature1 = "%.1f" % temperature1
  29.     return temperature1;
  30.    
  31. def getTemp2():
  32.     # Open the temperature sensor and read it and process the result
  33.     tfile = open("/sys/bus/w1/devices/28-0000038e53fe/w1_slave")
  34.     text = tfile.read()
  35.     tfile.close()
  36.     temperature_data2 = text.split()[-1]
  37.     temperature2 = float(temperature_data2[2:])
  38.     temperature2 = temperature2 / 1000
  39.     # Show only one decimal
  40.     temperature2 = "%.1f" % temperature2
  41.     return temperature2;
  42.  
  43. def getTemp3():
  44.     # Open the temperature sensor and read it and process the result
  45.     tfile = open("/sys/bus/w1/devices/28-0000038e5f2b/w1_slave")
  46.     text = tfile.read()
  47.     tfile.close()
  48.     temperature_data3 = text.split()[-1]
  49.     temperature3 = float(temperature_data3[2:])
  50.     temperature3 = temperature3 / 1000
  51.     # Show only one decimal
  52.     temperature3 = "%.1f" % temperature3
  53.     return temperature3;
  54.    
  55. while True:
  56.  
  57.     temp1 = getTemp1();
  58.     temp2 = getTemp2();
  59.     temp3 = getTemp3();
  60.  
  61.     errorTemp = -0.1
  62.    
  63.     if temp1 == errorTemp:
  64.         print('Possible error, getting Temp 1 again..')
  65.         temp1 = getTemp1();
  66.     elif temp2 == errorTemp:
  67.         print('Possible error, getting Temp 2 again..')
  68.         temp2 = getTemp2();
  69.     elif temp3 == errorTemp:
  70.         print('Possible error, getting Temp 3 again..')
  71.         temp3 = getTemp3();
  72.     else:
  73.         print('No error')
  74.    
  75.     if DEBUG:
  76.         print "Temp 1: ", temp1
  77.         print "Temp 2: ", temp2
  78.         print "Temp 3: ", temp3
  79.        
  80.     if LOGGER:
  81.         print('not in use right now..')
  82. #       # open up your cosm feed
  83. #       pac = eeml.Pachube(API_URL, API_KEY)
  84. #      
  85. #       #send celsius data
  86. #       pac.update([eeml.Data(0, temperature1, unit=eeml.Celsius())])
  87. #       pac.update([eeml.Data(1, temperature2, unit=eeml.Celsius())])
  88. #       pac.update([eeml.Data(2, temperature3, unit=eeml.Celsius())])
  89. #
  90. #       # send data to cosm
  91. #       pac.put()
  92.        
  93.     # Sleep for a minut to avoid flooding cosm
  94.     time.sleep(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement