Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import os
- import eeml
- import time
- DEBUG = 1
- LOGGER = 1
- os.system("sudo modprobe w1-gpio")
- os.system("sudo modprobe w1-therm")
- # COSM variables. The API_KEY and FEED are specific to your COSM account and must be changed
- # API_KEY = '5RNOO3ShYJxYiq2V2sgSRtz3112SAKxFQjNDQmNXc0RScz0g'
- # FEED = 68872
- # API_URL = '/v2/feeds/{feednum}.xml' .format(feednum = FEED)
- def getTemp1():
- # Open the temperature sensor and read it and process the result
- tfile = open("/sys/bus/w1/devices/28-0000038e4fc2/w1_slave")
- text = tfile.read()
- tfile.close()
- temperature_data1 = text.split()[-1]
- temperature1 = float(temperature_data1[2:])
- temperature1 = temperature1 / 1000
- # Show only one decimal
- temperature1 = "%.1f" % temperature1
- return temperature1;
- def getTemp2():
- # Open the temperature sensor and read it and process the result
- tfile = open("/sys/bus/w1/devices/28-0000038e53fe/w1_slave")
- text = tfile.read()
- tfile.close()
- temperature_data2 = text.split()[-1]
- temperature2 = float(temperature_data2[2:])
- temperature2 = temperature2 / 1000
- # Show only one decimal
- temperature2 = "%.1f" % temperature2
- return temperature2;
- def getTemp3():
- # Open the temperature sensor and read it and process the result
- tfile = open("/sys/bus/w1/devices/28-0000038e5f2b/w1_slave")
- text = tfile.read()
- tfile.close()
- temperature_data3 = text.split()[-1]
- temperature3 = float(temperature_data3[2:])
- temperature3 = temperature3 / 1000
- # Show only one decimal
- temperature3 = "%.1f" % temperature3
- return temperature3;
- while True:
- temp1 = getTemp1();
- temp2 = getTemp2();
- temp3 = getTemp3();
- errorTemp = -0.1
- if temp1 == errorTemp:
- print('Possible error, getting Temp 1 again..')
- temp1 = getTemp1();
- elif temp2 == errorTemp:
- print('Possible error, getting Temp 2 again..')
- temp2 = getTemp2();
- elif temp3 == errorTemp:
- print('Possible error, getting Temp 3 again..')
- temp3 = getTemp3();
- else:
- print('No error')
- if DEBUG:
- print "Temp 1: ", temp1
- print "Temp 2: ", temp2
- print "Temp 3: ", temp3
- if LOGGER:
- print('not in use right now..')
- # # open up your cosm feed
- # pac = eeml.Pachube(API_URL, API_KEY)
- #
- # #send celsius data
- # pac.update([eeml.Data(0, temperature1, unit=eeml.Celsius())])
- # pac.update([eeml.Data(1, temperature2, unit=eeml.Celsius())])
- # pac.update([eeml.Data(2, temperature3, unit=eeml.Celsius())])
- #
- # # send data to cosm
- # pac.put()
- # Sleep for a minut to avoid flooding cosm
- time.sleep(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement