#!/usr/bin/python import time import csv import urllib import urllib2 from Adafruit_BMP085 import BMP085 from xml.etree import ElementTree as ET from decimal import * location = 'COLDROOM' # set precision for output numeric data getcontext().prec = 5 # Initialise the BMP085 and use STANDARD mode (default value) # bmp = BMP085(0x77, debug=True) # bmp = BMP085(0x77) # To specify a different operating mode, uncomment one of the following: # bmp = BMP085(0x77, 0) # ULTRALOWPOWER Mode # bmp = BMP085(0x77, 1) # STANDARD Mode # bmp = BMP085(0x77, 2) # HIRES Mode bmp = BMP085(0x77, 3) # ULTRAHIRES Mode temp = bmp.readTemperature() # Read the current barometric pressure level pressure = bmp.readPressure() # To calculate altitude based on an estimated mean sea level pressure # (1013.25 hPa) call the function as follows, but this won't be very accurate altitude = bmp.readAltitude() # To specify a more accurate altitude, enter the correct mean sea level # pressure level. For example, if the current pressure level is 1023.50 hPa # enter 102350 since we include two decimal places in the integer value # altitude = bmp.readAltitude(102350) insidetemp = Decimal(temp) * 9 / 5 + 32 print "Inside Temp (sitting): %.2f F" % insidetemp #print "Pressure: %.2f hPa" % (pressure / 100.0) #print "Altitude: %.2f" % altitude # get current temp from NOAA for RDU url = 'http://w1.weather.gov/xml/current_obs/KRDU.xml' response = urllib2.urlopen(url) xml = response.read() # print xml #wind_degrees = ET.fromstring(xml).find('wind_degrees') # wind_gust_mph = ET.fromstring(xml).find('wind_gust_mph') wind_mph = ET.fromstring(xml).find('wind_mph') temp_c = ET.fromstring(xml).find('temp_c') outsidetemp = Decimal(temp_c.text) * 9 / 5 + 32 # get time in format 1/17/2014 08:23 PM curdttm = time.strftime("%m/%d/%Y %I:%M %p") # output line format: # current date/time, inside-temp, outside-temp,windspeed with open('/home/pi/templog.csv','a') as csvfile: csvwriter = csv.writer(csvfile,delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) csvwriter.writerow([location,curdttm,insidetemp,outsidetemp,wind_mph.text])