def read_sensors():
    global session, date_time, lat, lon, temp, humid
    try:
        report = session.next()
        # Wait for a 'TPV' report and display the current time
        # To see all report data, uncomment the line below
        if report['class'] == 'TPV':
            if hasattr(report, 'time'):
                #print 'time\t\t', report.time
                date_time = report.time
            if hasattr(report, 'lat'):
                #print 'latitude\t', report.lat
                lat = report.lat
            if hasattr(report, 'lon'):
                #print 'longitude\t', report.lon
                lon = report.lon
            #print 'temperature\t', htu.read_temperature()
            #print 'humidity\t', htu.read_humidity()
            temp = htu.read_temperature()
            humid = htu.read_humidity()
            path_writer.writerow([date_time, lat, lon, temp, humid])
    
    except KeyError:
        pass
    except StopIteration:
        session = None
        print "GPSD has terminated"
Esempio n. 2
0
def prog(filename="/home/pi/data/htu21df.log", sleeptime=3600):
	while True:
		# reset sensor and collect data for next log entry.
		HTU21DF.htu_reset
		temperature = HTU21DF.read_temperature()
		humidity = HTU21DF.read_humidity()
		cur_date = datetime.date.today()
		cur_time = time.time()
		data = [cur_date, cur_time, temperature, humidity]
	
		# save new data entry
		write_to_log(filename, data)
	
		# sleep until ready to collect next measurements.
		time.sleep(sleeptime)
Esempio n. 3
0
def getTemperature():
  tempList = []
  for x in range(100):
     HTU21DF.htu_reset
     tempList.append(
       celcius_to_fahrenheit(HTU21DF.read_temperature())
     )
  return median(tempList)
Esempio n. 4
0
def prog(filename):
	err=0
	try:
		print ("Reading humidity")
		HTU21DF.htu_reset
		humidity=HTU21DF.read_humidity()
		temp1=HTU21DF.read_temperature()
		time.sleep(5)
	except:
		print ("Failed")
		humidity="NA"
		temp1=0
		err=1
	try:
		print ("Reading the barometer")
		barometer = BMP085.BMP085(mode=BMP085.BMP085_ULTRAHIGHRES)
		pressure=barometer.read_pressure()
		temp2=barometer.read_temperature()
		time.sleep(5)
	except:
		print ("Failed")
		pressure="NA"
		temp2=0
		err=1
	if (temp1==0 or temp2==0):
		temp=temp1+temp2
	else:
		temp=(temp1+temp2)/2
	try:
		print ("Reading Lux level")
		lux=readLux()
		time.sleep(5)
	except:
		print ("Failed")
		lux=""
		err=1
	datetime=strftime("%Y-%m-%d\t%H:%M:%S")
	data=[datetime,temp,humidity,pressure,lux]
	# savenewdataentry
	write_to_log(filename,data)
	hour=strftime("%H")
        if int(hour) < 7: 
            write_lux("/home/pi/lux.csv",lux) 
	return err
# A simple program to test the driver

import time
import HTU21DF

while True:
	print("sending reset...")
	HTU21DF.htu_reset
	temperature = HTU21DF.read_temperature()
	print("The temperature is %f C." % temperature)
	time.sleep(1)
	humidity = HTU21DF.read_humidity()
	print("The humidity is %F percent." % humidity)
	time.sleep(1)
def getHumidity(temperature):
  tempList = []
  for x in range(50):
     HTU21DF.htu_reset
     tempList.append(HTU21DF.read_humidity(temperature))
  return median(tempList)
def getTemperature():
  HTU21DF.htu_reset()
  return HTU21DF.read_temperature()
Esempio n. 8
0
import time
import HTU21DF



def median(x):
  m,r= divmod(len(x),2)
  if r:
    return sorted(x)[m]
  return sum(sorted(x)[m-1:m+1])/2

def average(x):
  return sum(x)/len(x)


tempList = []
for x in range(1000):
   HTU21DF.htu_reset
   tempList.append(HTU21DF.read_temperature())


print 'median is {0}'.format(median(tempList))
print 'average is {0}'.format(average(tempList))
print 'minimum value is {0}, maximum value is {1}'.format(min(tempList), max(tempList))
print 'difference is {0}'.format(max(tempList) - min(tempList))