API_KEY = 'YOUR API KEY' API_URL = '/v2/feeds/79839.xml' port = '/dev/tty.usbserial-A600eoro' ser = serial.Serial(port, 9600, timeout=20) while True: data = ser.readline() if len(data) > 0: data = string.split(data, ':') pprint.pprint(data) try: print "Temperature is " + data[0] + " and lux is " + data[1] # Log data to cosm pac = eeml.Pachube(API_URL, API_KEY) pac.update([ eeml.Data('Temperature', data[0], unit=eeml.Fahrenheit()), eeml.Data('Lux', data[1]) ]) pac.put() sleep(10) except Exception, err: print "data error" ser.close()
# remove decimal point from millivolts millivolts = "%d" % millivolts # show only one decimal place for temprature and voltage readings temp_C = "%.1f" % temp_C temp_F = "%.1f" % temp_F if DEBUG: print "read_adc0:\t", read_adc0 print "millivolts:\t", millivolts print "temp_C:\t\t", temp_C print "temp_F:\t\t", temp_F print if LOGGER: # open up your cosm feed pac = eeml.Pachube(API_URL, API_KEY) #send celsius data pac.update([eeml.Data(0, temp_C, unit=eeml.Celsius())]) #send fahrenheit data pac.update([eeml.Data(1, temp_F, unit=eeml.Fahrenheit())]) # send data to cosm pac.put() # hang out and do nothing for 10 seconds, avoid flooding cosm time.sleep(10)
humidity = float(matches.group(1)) if DEBUG: print "dht22 Temperature: %.1f F" % btempF print "Humidity: %.1f %%" % humidity # =========================================================================== # open up cosm feed # =========================================================================== pac = eeml.Pachube(API_URL, API_KEY) # =========================================================================== # send temperature data # =========================================================================== pac.update([eeml.Data(0, temp, unit=eeml.Fahrenheit())]) # =========================================================================== # send pressure data # =========================================================================== pac.update([eeml.Data(1, pressure, unit=eeml.Unit('Pressure', type='basicSI', symbol="in."))]) # =========================================================================== # send humidity data # =========================================================================== pac.update([eeml.Data(2, humidity, unit=eeml.Unit('Humidity', type='basicSI', symbol="%"))]) # =========================================================================== # send data to cosm # =========================================================================== pac.put() time.sleep(60)
sensor1 = Temp(fileName='28-000004d93f9d') sensor2 = Temp(fileName='28-000004d9ad58') sensor1.start() sensor2.start() #the rest of your code is below. # The Temp class will be updating on its own thread which will allow you to do # anything you want on the main thread. while True: temp1 = sensor1.getCurrentTemp() temp2 = sensor2.getCurrentTemp() print temp1 print temp2 #open cosm feed pac = eeml.Pachube(API_URL, API_KEY) #send fahrenheit data pac.update([eeml.Data('Fermenter_Temp', temp1, unit=eeml.Fahrenheit())]) pac.update([eeml.Data('Closet_Temp', temp2, unit=eeml.Fahrenheit())]) #send data to cosm # if((temp1 > 55 and temp1 < 110) and (temp2 >50 and temp2 <110)): if ((temp1 > 40) and (temp1 < 110) and (temp2 > 40) and (temp2 < 110)): pac.put() #hang out and do nothing for 30 seconds, dont flood cosm time.sleep(30)
outfile = "/var/tmp/wattstemphumid" while True: # create an empty list myList = [] # read from serial data = ser.read(9999) # split the data at commas # data is in the format: watthours,fahrenheit,humidiity myList = data.split(",") if len(myList) == 3: # open feed pac = eeml.Pachube(API_URL, API_KEY) # compile data pac.update([eeml.Data("Watthours", myList[0], unit=eeml.Unit(name='watt', type='derivedSI', symbol='W'))]) pac.update([eeml.Data("Temperature", myList[1], unit=eeml.Fahrenheit())]) pac.update([eeml.Data("Humidity", myList[2], unit=eeml.RH())]) # send the data try: pac.put() except: print "update failed" # write data to file try: f = open(outfile,"w") f.write(myList[0] + "," + myList[1] + "," + myList[2]) f.flush() f.close() except: print "Unable to write to file %s" % (outfile) sleep(0.5)