def setup(): global dht GPIO.setmode(GPIO.BOARD) GPIO.setup(irrigationPin, GPIO.OUT, initial=GPIO.LOW) #Setup relay GPIO.setup(pirPin, GPIO.IN) #Setup pir dht = DHT.DHT(dhtPin) #Setup dht LCD.lcd_setup() #Setup lcd
def __init__(self, server_name, max_data_size, lock_size): self.lock_size = lock_size self.lock_map = dict() self.init_locks() self.lock_con = threading.Lock() self.max_data_size = max_data_size self.connections = [] self.node_info = config.nodes self.server_name = server_name self.dht_table = DHT.DHT(self.server_name) self.put_nums = 0 self.initial() self.ring = consist_hash().h_ring()
def createInstances(self): for o in sensorList: if self.instancesList.getData(None, o['name']) is None: if o['name'][0:3] == 'dht': instance = DHT(o['name'], o['pin'][0]) self.instancesList.addData(instance) elif o['name'][0:3] == 'hcr': instance = HCR(o['name'], o['pin'][0], o['pin'][1]) self.instancesList.addData(instance) elif o['name'][0:3] == 'pir': instance = PIR(o['name'], o['pin'][0]) self.instancesList.addData(instance) else: print('error al generar instancia')
def loop(): dht = DHT.DHT(DHTPin) #create a DHT class object sumCnt = 0 #number of reading times while (True): sumCnt += 1 #counting number of reading times chk = dht.readDHT11( ) #read DHT11 and get a return value. Then determine whether data read is normal according to the return value. print("The sumCnt is : %d, \t chk : %d" % (sumCnt, chk)) if ( chk is dht.DHTLIB_OK ): #read DHT11 and get a return value. Then determine whether data read is normal according to the return value. print("DHT11,OK!") elif (chk is dht.DHTLIB_ERROR_CHECKSUM): #data check has errors print("DHTLIB_ERROR_CHECKSUM!!") elif (chk is dht.DHTLIB_ERROR_TIMEOUT): #reading DHT times out print("DHTLIB_ERROR_TIMEOUT!") else: #other errors print("Other error!") print("Humidity : %.2f, \t Temperature : %.2f \n" % (dht.humidity, dht.temperature)) time.sleep(3)
from DHT import * from HCR import * from PIR import * from File import * import os import time newDHT = DHT() newHCR = HCR() newPIR = PIR() newFile = File() array = [] newFile.readData("Respaldo") try: while True: if os.path.isfile("Respaldo2.txt"): #print("Existe") file = open("Respaldo2.txt", "a") else: #print("No existe") file = open("Respaldo2.txt", "w") newDHT.leerTemperatura() newDHT.guardarDatosSQL() newDHT.guardarDatosMongo() #print(newDHT.retornarDatos()) newPIR.leerPrescencia() newPIR.guardarDatosPIRSQL() newPIR.guardarDatosPIRMongo() #print(newPIR.retornarDatosPIR()) newHCR.leerDistancia() newHCR.guardarDatosSQL() newHCR.guardarDatosMongo()