def read(sensor, pin): # Validate pin is a valid GPIO. if pin is None or int(pin) < 0 or int(pin) > 31: raise ValueError('Pin must be a valid GPIO number 0 to 31.') # Get a reading from C driver code. result, humidity, temp = driver.read(sensor, int(pin)) if result in common.TRANSIENT_ERRORS: # Signal no result could be obtained, but the caller can retry. return (None, None) elif result == common.DHT_ERROR_GPIO: raise RuntimeError('Error accessing GPIO. Make sure program is run as root with sudo!') elif result != common.DHT_SUCCESS: # Some kind of error occured. raise RuntimeError('Error calling DHT test driver read: {0}'.format(result)) return (humidity, temp)
def read(sensor, sample): # Validate sample is a positive integer. if sample is None or int(sample) < 0: raise ValueError('Sample must be a positive integer.') # Get a reading from C driver code. result, density = driver.read(sensor, int(sample)) if result in common.TRANSIENT_ERRORS: # Signal no result could be obtained, but the caller can retry. return None elif result == common.GP2Y10_ERROR_GPIO: raise RuntimeError('Error accessing GPIO. Make sure program is run as root with sudo!') elif result == common.GP2Y10_ERROR_SERIAL: raise RuntimeError('Error accessing serial. Make sure program is run as root with sudo!') elif result != common.GP2Y10_SUCCESS: # Some kind of error occured. raise RuntimeError('Error calling GP2Y10 test driver read: {0}'.format(result)) return density
def read(sensor, pin): # Validate pin is a valid GPIO. if pin is None or int(pin) < 0 or int(pin) > 31: raise ValueError('Pin must be a valid GPIO number 0 to 31.') # Get a reading from C driver code. result, humidity, temp = driver.read(sensor, int(pin)) if result in common.TRANSIENT_ERRORS: # Signal no result could be obtained, but the caller can retry. return (None, None) elif result == common.DHT_ERROR_GPIO: raise RuntimeError( 'Error accessing GPIO. Make sure program is run as root with sudo!' ) elif result != common.DHT_SUCCESS: # Some kind of error occured. raise RuntimeError( 'Error calling DHT test driver read: {0}'.format(result)) return (humidity, temp)
SenseurDHT('Cuisine', "1.3.6.1.4.1.43689.1.2.2.1.0", "1.3.6.1.4.1.43689.1.2.2.2.0", 8), SenseurDHT('ThermoOld', "1.3.6.1.4.1.43689.1.2.9.1.0", "1.3.6.1.4.1.43689.1.2.9.2.0", 9), SenseurDHT('ThermoNew', "1.3.6.1.4.1.43689.1.2.10.1.0", "1.3.6.1.4.1.43689.1.2.10.2.0", 10), SenseurDHT('SdbNew', "1.3.6.1.4.1.43689.1.2.12.1.0", "1.3.6.1.4.1.43689.1.2.12.2.0", 11), SenseurDHT('Rasp', "1.3.6.1.4.1.43689.1.2.13.1.0", "1.3.6.1.4.1.43689.1.2.13.2.0", 25), # SenseurDHT('SdbOld', "1.3.6.1.4.1.43689.1.2.11.1.0", "1.3.6.1.4.1.43689.1.2.11.2.0", pinSdbOld), ] self.allSenseurs = {} for senseur in senseurList : GPIO.setup(senseur.pin, GPIO.IN) senseur.getDhtValues() self.allSenseurs[senseur.label] = senseur # print "Humidity : ",senseur.label, dic[senseur.label].toSnmpSetHum() # print "Temperature : ",senseur.label, dic[senseur.label].toSnmpSetTemp() def Dht(): allSenseurs = DhtDef() return allSenseurs if __name__ == "__main__": while 1==1: # pins = [4,9,11,17,27] pins = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27] for i in pins : result = driver.read(22,i) if 0 == result[0]: print("%d (%d,%d,%d)"%((i,)+result)) time.sleep(1)