当前位置: 首页>>代码示例>>Python>>正文


Python Adafruit_DHT.read_retry方法代码示例

本文整理汇总了Python中Adafruit_DHT.read_retry方法的典型用法代码示例。如果您正苦于以下问题:Python Adafruit_DHT.read_retry方法的具体用法?Python Adafruit_DHT.read_retry怎么用?Python Adafruit_DHT.read_retry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Adafruit_DHT的用法示例。


在下文中一共展示了Adafruit_DHT.read_retry方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read_and_log

# 需要导入模块: import Adafruit_DHT [as 别名]
# 或者: from Adafruit_DHT import read_retry [as 别名]
def read_and_log(loc_dic):
    try:
        humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, set_dic['gpio_dht22sensor'])
        if humidity == None or temperature == None or humidity > 101:
            print(" -- problem reading sensor on GPIO:"+set_dic['gpio_dht22sensor']+"--")
            return '-1','-1','-1'
        else:
            humidity = round(humidity,2)
            temperature = round(temperature, 2)
            timno = datetime.datetime.now()
            try:
                with open(loc_dic['loc_dht_log'], "a") as f:
                    line = str(temperature) + '>' + str(humidity) + '>' + str(timno) + '\n'
                    f.write(line)
            except:
                print["-LOG ERROR-"]
                pigrow_defs.write_log('checkDHT.py', 'writing dht log failed', loc_dic['err_log'])
            return humidity, temperature, timno
    except:
        print(" -- problem reading sensor on GPIO:"+set_dic['gpio_dht22sensor']+"--")
        return '-1','-1','-1'

#
#   Device control logic
# 
开发者ID:Pragmatismo,项目名称:Pigrow,代码行数:27,代码来源:checkDHT.py

示例2: make_dht11_sensors

# 需要导入模块: import Adafruit_DHT [as 别名]
# 或者: from Adafruit_DHT import read_retry [as 别名]
def make_dht11_sensors(wiring_config):
    """Creates sensors derived from the DHT11 sensor.

    Args:
        wiring_config: Wiring configuration for the GreenPiThumb.

    Returns:
        A two-tuple where the first element is a temperature sensor and the
        second element is a humidity sensor.
    """
    local_dht11 = dht11.CachingDHT11(
        lambda: Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, wiring_config.gpio_pins.dht11),
        clock.Clock())
    return temperature_sensor.TemperatureSensor(
        local_dht11), humidity_sensor.HumiditySensor(local_dht11), 
开发者ID:JeetShetty,项目名称:GreenPiThumb,代码行数:17,代码来源:greenpithumb.py

示例3: read_temperature

# 需要导入模块: import Adafruit_DHT [as 别名]
# 或者: from Adafruit_DHT import read_retry [as 别名]
def read_temperature(self):
        humidity, temperature = Adafruit_DHT.read_retry(11, 4)
	print "Temperature read by DHT11: " + str(int(temperature))
        return temperature 
开发者ID:davikawasaki,项目名称:iot-security-vulnerability,代码行数:6,代码来源:Temperature.py

示例4: take_reading

# 需要导入模块: import Adafruit_DHT [as 别名]
# 或者: from Adafruit_DHT import read_retry [as 别名]
def take_reading(self):
        h, t = Adafruit_DHT.read_retry(self.model, self.pin)
        if self.fahrenheit:
            t = ((9/5) * t) + 32
        self.temperature.emit(t)
        self.humidity.emit(h)
        self.read_time.emit(qtc.QTime.currentTime()) 
开发者ID:PacktPublishing,项目名称:Mastering-GUI-Programming-with-Python,代码行数:9,代码来源:temp_humid_display.py

示例5: read

# 需要导入模块: import Adafruit_DHT [as 别名]
# 或者: from Adafruit_DHT import read_retry [as 别名]
def read(self):
		#Read the sensor(s), parse the data and store it in redis if redis is configured

		humidity, temperature = Adafruit_DHT.read_retry(self.sensor, self.pin)
		
		if humidity is not None and temperature is not None:
			variables.r.set(self.key + '_temperature', round(temperature * 1.8 + 32, 2))
			variables.r.set(self.key + '_humidity', humidity)
			readings = {'temperature': round(temperature * 1.8 + 32, 2), 'humidity': humidity}
			variables.r.set(self.key, json.dumps(readings))
			print('Pi Temp:', readings)
			return readings
		else:
			print('Failed to get reading. Try again!') 
开发者ID:mudpi,项目名称:mudpi-core,代码行数:16,代码来源:humidity_sensor.py

示例6: read_temp

# 需要导入模块: import Adafruit_DHT [as 别名]
# 或者: from Adafruit_DHT import read_retry [as 别名]
def read_temp():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = float(temp_string) / 1000.0
        temp_f = temp_c * 9.0 / 5.0 + 32.0
        return temp_f

# Try to grab a sensor reading.  Use the read_retry method which will retry up
# to 15 times to get a sensor reading (waiting 2 seconds between each retry). 
开发者ID:JeremyMorgan,项目名称:Raspberry_Pi_Temperature,代码行数:16,代码来源:temp-humidity.py

示例7: read_raw

# 需要导入模块: import Adafruit_DHT [as 别名]
# 或者: from Adafruit_DHT import read_retry [as 别名]
def read_raw(self):
        return adafruit_dht.read_retry(self.dht22, 4) 
开发者ID:aws-samples,项目名称:aws-builders-fair-projects,代码行数:4,代码来源:dht22.py

示例8: collect_temperature

# 需要导入模块: import Adafruit_DHT [as 别名]
# 或者: from Adafruit_DHT import read_retry [as 别名]
def collect_temperature():    
    humidity, temperature = Adafruit_DHT.read_retry(sensor_temperature, channel_temperature)
    logger.info("humidity: {} temperature: {}".format(humidity, temperature))
    if humidity is not None and temperature is not None:
        return humidity, temperature
    logger.error("Falha ao ler dados do DHT11")
    return 0, 0
    

#GPIO.add_event_detect(channel, GPIO.BOTH)
#GPIO.add_event_callback(channel, collect_moisture) 
开发者ID:aws-samples,项目名称:aws-builders-fair-projects,代码行数:13,代码来源:moistureHandler.py

示例9: collect_moisture

# 需要导入模块: import Adafruit_DHT [as 别名]
# 或者: from Adafruit_DHT import read_retry [as 别名]
def collect_moisture(channel):
    # Efetua a leitura do sensor
    umid, temp = 0,0
    #umid, temp = Adafruit_DHT.read_retry(sensor, 4)    
    # Caso leitura esteja ok, mostra os valores na tela
    if umid is not None and temp is not None:
        print ("Temperatura = {0:0.1f}  Umidade = {1:0.1f}n").format(temp, umid)
        print ("Aguarda 5 segundos para efetuar nova leitura...n")
        publishTemperature(temp, umid)
    else:
        # Mensagem de erro de comunicacao com o sensor
        print("Falha ao ler dados do DHT11 !!!")

#GPIO.add_event_detect(channel, GPIO.BOTH)
#GPIO.add_event_callback(channel, collect_moisture) 
开发者ID:aws-samples,项目名称:aws-builders-fair-projects,代码行数:17,代码来源:temperatureHandler.py

示例10: read_temp_sensor

# 需要导入模块: import Adafruit_DHT [as 别名]
# 或者: from Adafruit_DHT import read_retry [as 别名]
def read_temp_sensor(sensor):
    try:
        humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, sensor_gpio)
        if humidity == None or temperature == None or humidity > 101:
            print("--problem reading sensor on GPIO:"+sensor_gpio+"--")
            return '-1','-1','-1'
        else:
            humidity = round(humidity,2)
            temperature = round(temperature, 2)
            logtime = datetime.datetime.now()
            return humidity, temperature, logtime
    except:
        print("--problem reading sensor on GPIO:"+sensor_gpio+"--")
        return '-1','-1','-1' 
开发者ID:Pragmatismo,项目名称:Pigrow,代码行数:16,代码来源:log_auxdht22.py

示例11: readSensor

# 需要导入模块: import Adafruit_DHT [as 别名]
# 或者: from Adafruit_DHT import read_retry [as 别名]
def readSensor(self):

        resultHum = None
        resultTemp = None

        valueHum, valueTemp = Adafruit_DHT.read_retry(self.sensor, self.pin, 2)
        #print("Raw reading H:{0} T:{1}".format(valueHum, valueTemp ))

        # Is humidity and temperature reading valid?
        if ((self.isReadingValid(valueHum, 0.0, 100.0)) and (self.isReadingValid(valueTemp, -40.0, 125.0))):
            self.arrHumidity.append(round(valueHum, 2))
            valueTemp = self.convertTemp(valueTemp);
            self.arrTemperature.append(round(valueTemp, 2))
        else:
            #Reading out of bounds
            return resultHum, resultTemp
    
        if (len(self.arrHumidity)>self.ARRAY_SIZE):
            del self.arrHumidity[0]

        if (len(self.arrTemperature)>self.ARRAY_SIZE):
            del self.arrTemperature[0]

        if (self.sensorMode == "Advanced"):
            sumHum = sum(filter(None, self.arrHumidity))
            noHumReadings = len(filter(None, self.arrHumidity))
            if (noHumReadings>0):
                resultHum = float(str(round(sumHum/noHumReadings, self.precissionHum)))

            sumTemp = sum(filter(None, self.arrTemperature))
            noTempReadings = len(filter(None, self.arrTemperature))
        
            if (noTempReadings>0):
                resultTemp = float(str(round(sumTemp/noTempReadings, self.precissionTemp)))

            #print("readValueAdvanced: Result - Hum:'{0}', Temp:'{1}'".format(resultHum, resultTemp))
            self.logger.info("readValue: Hum:'{0}', Temp:'{1}'".format(resultHum, resultTemp))

        #Simple mode -> Just return last reading
        else:
            resultHum =  float(str(round(valueHum, self.precissionHum)))
            resultTemp = float(str(round(valueTemp, self.precissionTemp)))

            self.logger.info("readValue: Hum:'{0}', Temp:'{1}'".format(resultHum, resultTemp))

            #print("readValueSimple: Result - Hum:'{0}', Temp:'{1}'".format(resultHum, resultTemp))

        return resultHum, resultTemp 
开发者ID:rkoshak,项目名称:sensorReporter,代码行数:50,代码来源:DHTSensor.py

示例12: read_handler

# 需要导入模块: import Adafruit_DHT [as 别名]
# 或者: from Adafruit_DHT import read_retry [as 别名]
def read_handler(vpin):
    # DHT22
    dht22_sensor = Adafruit_DHT.DHT22  # possible sensor modifications .DHT11 .DHT22 .AM2302. Also DHT21 === DHT22
    humidity, temperature = Adafruit_DHT.read_retry(dht22_sensor, GPIO_DHT22_PIN, retries=5, delay_seconds=1)
    Counter.cycle += 1
    # check that values are not False (mean not None)
    if all([humidity, temperature]):
        print('temperature={} humidity={}'.format(temperature, humidity))
        if temperature <= T_CRI_VALUE:
            blynk.set_property(T_VPIN, 'color', T_CRI_COLOR)
            # send notifications not each time but once a minute (6*10 sec)
            if Counter.cycle % 6 == 0:
                blynk.notify(T_CRI_MSG)
                Counter.cycle = 0
        else:
            blynk.set_property(T_VPIN, 'color', T_COLOR)
        blynk.set_property(H_VPIN, 'color', H_COLOR)
        blynk.virtual_write(T_VPIN, temperature)
        blynk.virtual_write(H_VPIN, humidity)
    else:
        print('[ERROR] reading DHT22 sensor data')
        blynk.set_property(T_VPIN, 'color', ERR_COLOR)  # show aka 'disabled' that mean we errors on data read
        blynk.set_property(H_VPIN, 'color', ERR_COLOR)

    # BMP180
    bmp180_sensor = BMP085.BMP085(busnum=1)
    pressure = bmp180_sensor.read_pressure()
    altitude = bmp180_sensor.read_altitude()
    # check that values are not False (mean not None)
    if all([pressure, altitude]):
        print('pressure={} altitude={}'.format(pressure, altitude))
        blynk.set_property(P_VPIN, 'color', P_COLOR)
        blynk.set_property(A_VPIN, 'color', A_COLOR)
        blynk.virtual_write(P_VPIN, pressure / 133.322)  # mmHg  1mmHg = 133.322 Pa
        blynk.virtual_write(A_VPIN, altitude)
    else:
        print('[ERROR] reading BMP180 sensor data')
        blynk.set_property(P_VPIN, 'color', ERR_COLOR)  # show aka 'disabled' that mean we errors on data read
        blynk.set_property(A_VPIN, 'color', ERR_COLOR)


###########################################################
# infinite loop that waits for event
########################################################### 
开发者ID:blynkkk,项目名称:lib-python,代码行数:46,代码来源:01_weather_station_pi3b.py


注:本文中的Adafruit_DHT.read_retry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。