/** * ESP8266-12E / NodeMCU / WeMos D1 Mini WiFi & ENC28J60 Sample * Source code can be found here: https://github.com/JZ-SmartThings/SmartThings/blob/master/Devices/Generic%20HTTP%20Device * Copyright 2018 JZ * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at: * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License * for the specific language governing permissions and limitations under the License. */ ///////////////////////////////////////// #include // Use library version 1.2.3 as 1.3.0 gives error #include #include #include #include #include #include const char* ssid = "MY WIFI NETWORK"; const char* password = "MY WIFI PASSWORD"; #define DHTPIN D7 // what pin is the DHT on? // Uncomment whatever type of temperature sensor you're using! //#define DHTTYPE DHT11 // DHT 11 #define DHTTYPE DHT22 // DHT 22 (AM2302) DHT dht(DHTPIN, DHTTYPE); MDNSResponder mdns; String currentIP, clientIP, request, fullrequest; char *clientIPchar; WiFiServer server(80); ESP8266WebServer irserver(81); IRsend irsend(4); ///////////////////////////////////////// void handleRoot() { irserver.send(200, "text/html", " KeepRite AC Control

KeepRite AC Control

AC On

AC Off

Turbo

Air Direction

Swing

"); } void handleIr(){ for (uint8_t i=0; i\n"); clientResponse.concat("ESP8266"); clientResponse.concat("\n\n"); clientResponse.concat("\n"); clientResponse.concat(""); clientResponse.concat("\n

NodeMCU"); clientResponse.concat("

"); clientResponse.concat(currentIP); clientResponse.concat("\n

\n"); clientResponse.concat("Current Request:
\n"); clientResponse.concat(request); clientResponse.concat("\n
"); clientResponse.concat("
\n");
// SHOW & HANDLE DHT
      clientResponse.concat("DHT");
      clientResponse.concat(DHTTYPE);
      clientResponse.concat(" Sensor Information:\n");
      float h = processDHT(0);
      float tc = processDHT(1); float tf = (tc * 9.0 / 5.0) + 32.0;
      if (tc == -1000) {
        clientResponse.concat("DHT Temperature Reading Failed\n");
      } else {
        clientResponse.concat("Temperature="); clientResponse.concat(String(tc, 1)); clientResponse.concat((char)176); clientResponse.concat("C "); clientResponse.concat(round(tf)); clientResponse.concat((char)176); clientResponse.concat("F\n");
      }
      if (h == -1000) {
        clientResponse.concat("DHT Humidity Reading Failed\n");
      } else {
        clientResponse.concat("Humidity="); clientResponse.concat(round(h)); clientResponse.concat("%\n");
      }
    clientResponse.concat("
\n"); clientResponse.concat("
\n"); clientResponse.concat("\n"); } return clientResponse; }// End Client Response ///////////////////////////////////////// float processDHT(bool whichSensor) { // Reading temperature or humidity takes about 250 milliseconds. Sensor readings may also be up to 2 seconds old float h = -1000; float tc = -1000; int counter = 1; if (whichSensor == 0) { h = dht.readHumidity(); while (counter <= 5 && (isnan(h) || h == -1000)) { if (isnan(h) || h == -1000) { h = dht.readHumidity(); } // re-read counter += 1; delay(50); } } else if (whichSensor == 1) { tc = dht.readTemperature(); while (counter <= 5 && (isnan(tc) || tc == -1000)) { if (isnan(tc) || tc == -1000) { tc = dht.readTemperature(); } // re-read counter += 1; delay(50); } } if (whichSensor == 0) { if (isnan(h) || h == -1000) { return -1000; } else { return h; } } else if (whichSensor == 1) { if (isnan(tc) || tc == -1000) { return -1000; } else { return tc; } } }// End Process DHT