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"
Exemplo n.º 2
0
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"
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
0
def prog(filename="/home/pi/behaviorRoomEnv.log", sleeptime=600):
    while True:
        # reset sensor and collect data for next log entry.
        temp = tempsensor.readTempC()
        humidity = HTU21DF.read_humidity()
        tempPres = MPL3115A2.pressure()
        lux = readLux()
        ## calculate average lux for 100 readings
        datetime = strftime("%Y-%m-%d\t%H:%M:%S")
        data = [datetime, temp, humidity, tempPres[1], lux]

        # save new data entry
        write_to_log(filename, data)

        # sleep until ready to collect next measurements.
        time.sleep(sleeptime)
Exemplo n.º 6
0
def sensorReadingProcess(logfileLock, filename, sleeptime):
    while True:
        # reset sensor and collect data for next log entry.
        # TODO: Make this section of code resistant to hardware failures by inserting "nil" values for missing data when appropriate
        temp = tempsensor.readTempC()
        humidity = HTU21DF.read_humidity()
        tempPres = MPL3115A2.pressure()
        lux = readLux()
        ## calculate average lux for 100 readings
        datetime = strftime("%Y-%m-%d\t%H:%M:%S")
        data = [datetime, temp, humidity, tempPres[1], lux]

        # save new data entry, blocking I/O operation
        logfileLock.acquire()
        write_to_log(filename, data)
        logfileLock.release()
        # sleep until ready to collect next measurements.
        time.sleep(sleeptime)
Exemplo n.º 7
0
def prog(filename):
    # reset sensor and collect data.
    # reset sensor and collect data.  temp=tempsensor.readTempC()
    HTU21DF.htu_reset
    humidity = HTU21DF.read_humidity()
    temp1 = HTU21DF.read_temperature()
    barometer = BMP085.BMP085(mode=BMP085.BMP085_ULTRAHIGHRES)
    pressure = barometer.read_pressure()
    temp2 = barometer.read_temperature()
    temp = (temp1 + temp2) / 2
    lux = readLux()
    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 float(hour) < 7:
        write_lux("/home/pi/lux.csv", lux)
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
Exemplo n.º 9
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
Exemplo n.º 10
0
def ReadSensors():
    global measuredTemp
    global measuredHumidity
    global reportCount
    global reportEvery

    measuredTemp = HTU21DF.read_temperature()
    measuredHumidity = HTU21DF.read_humidity()
    displayValues(
        str(round(measuredTemp, 1)) + " deg C",
        str(round(measuredHumidity, 1)) + " %")

    if (reportCount == reportEvery):
        # Send data to the web service
        reqString = 'http://api.marc-jennings.co.uk/InsecureUploadOfData.php?temperature=' + str(
            measuredTemp) + '&humidity=' + str(measuredHumidity)
        req = urllib2.Request(reqString)
        resp = urllib2.urlopen(req)

    reportCount = reportCount + 1
    if (reportCount > reportEvery):
        reportCount = 1
# 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)
Exemplo n.º 13
0
 def read_values(self):
     logging.info('Performing measurement ...')
     self._temperature = HTU21DF.read_temperature()
     self._humidity = HTU21DF.read_humidity()
     logging.info('Got measurement: temperature: {}, humidity: {}'.format(
         self._temperature, self._temperature))