#ifndef SensorDHTDef #define SensorDHTDef 1 #include "defines.h" #include class SensorDHT: public DomoEspSensorReceiver { SimpleDHT22 dht; uint8_t pin; float t,h; public: virtual float getVal() { return t; } SensorDHT() { pin=0; t=h=0; topic[0]=0; } void set(uint8_t _pin, const char* topic_id) { pin=_pin; t=h=9.99998; strcpy(topic, topic_id); } virtual void procesa(IMqttManager * man, int tiempo) { if(tiempo==0) return; #ifdef DEBUG_PS Serial.println("ProcesaDHT"); #endif float ta,ha; for(int i=0; i<4; i++) { if (dht.read2(pin, &ta, &ha, NULL) != SimpleDHTErrSuccess) { delay(20); continue; } else { /*if(t==h && t==9.99998) {*/ t=ta; h=ha; /*} else { t=(t+ta)/2; h=(h+ha)/2; }*/ break; } } if(tiempo==2) { #ifdef DEBUG_PS Serial.println("LogDHT"); #endif //loguea------------ //char buffer_t[MAXTOPICVAR]; //char buffer_p[MAXTOPICVAR]; //temperatura----------------- dtostrf(t,3, 2, buffer_p); sprintf(buffer_t, "%s/t/get",topic); man->MqttSend(buffer_t, buffer_p); //humedad----------------- dtostrf(h,3, 2, buffer_p); sprintf(buffer_t, "%s/h/get",topic); man->MqttSend(buffer_t, buffer_p); } } }; #endif