#define TEMP_SENSOR_PIN 12 #define HUMIDITY_SENSOR_PIN 12 #define FAN_PIN 15 #define CO2_PIN 16 #define ULTRASONIC_PIN 17 #define CHECK_FREQUENCY 2 // check sensors every 2 seconds #define HUMIDITY_DESIRED 75 #define HUMIDITY_VARIATION 3 // ultrasonic turns on at (75 - 3 = 72) and off // at (75 + 3 = 78) #include "ota.h" // Tempature + Humidity Sensor #include #include #define DHTPIN 12 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); WiFiClient *wific = 0; void setup () { setupWifi((char *) hostname); setupOTA((char *) hostname); Serial.begin(115200); Serial.println(F("Mushing...")); dht.begin(); // temp+humidity sensor wific = new WiFiClient(); } void log_reading ( float temp_c, float humidity, float heat_index_c ) { auto fmt = "T: %.2f H: %.2f HI: %.2f\r\n"; char buf[500]; snprintf(buf, sizeof(buf), fmt, temp_c, humidity, heat_index_c); //Serial.printf(fmt, temp_c, humidity, heat_index_c); Serial.print(buf); if (wific->connected()) { wific->write(buf); } } void loop() { ArduinoOTA.handle(); auto ip = IPAddress(192,168,1,2); auto port = 3141; if (!wific->connected()) { Serial.println("Attempting to connect"); wific->connect(ip, port); } // Wait a few seconds between measurements. delay(2000); float h = dht.readHumidity(); float t = dht.readTemperature(); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t) ) { Serial.println(F("Failed to read from DHT sensor!")); return; } float hic = dht.computeHeatIndex(t, h, false); log_reading(t, h, hic); }