In these Project We are going to see how we can be controlling AC through Web Server using ESP8266 TSop1738 Receiver and IR led. These Project Consist of two part.


In the First Part We are going to Decode the Ac Remote Buttons to get hexcode, AC status and Raw Data.
In the Second we will encode those code in ESP8266 and control AC using Webserver hosted on ESP8266 with IR led.

Part 1
Material Required

1) Nodemcu board
2) TSOP1738 IR reciever or some other IR recievers
3) jumpers


Hardware Connections

Installing Required Libraries
1) Select “Sketch” from arduino toolbar
2) Select “Include Library” from there select “Manage libraries”
3) Search for “IRremoteESP8266” and install it

Arduino Code for Decoding the Ac remote
1) Open Arduino and connect the nodemcu to laptop or computer
2) From “Files” select example go down and from IRremoteESP8266 select the IRrecvDumpV2
3) Upload to nodemcu.

Output of the IRrecvDumpV2.ino
Press all the Buttons on the Ac remote that you want to Decode

These are the codes generated from IRrecvDumpV2 by pressing the temperature up Button. You can use any code from the above output to send it to Ac by IRLed for increasing the temperature. In this project we will be using the uint16_t rawData. Note down all the codes of turning an AC on, off, increasing temperture and decreasing the temperature.

Part 2: Encoding the Code in Esp8266
Component Required
1) Esp8266 NodeMCU
2) IRLed
3) Jumpers
4) Transistor

Hardware Connections

Source Code:
In these Code we have designed a html Webpage which control the Ac(On , Off , TemperatureUp,TemperatureDown)


Program:

How the Code Works?
1) Install the Required Libraries

#include <Arduino.h>
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#endif  // ESP8266
#if defined(ESP32)
#include <WiFi.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#endif  // ESP32
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <IRrecv.h>
#include <WiFiClient.h>
#include <IRutils.h>

2) Enter the Network Credentials

const char* kSsid = "Avotrix";
const char* kPassword = "9987197583";

3) Initialize the ESP8266WebServer on Port no 80

ESP8266WebServer server(80);

4) Initialize the IRLed Pin to send the Signal. We have set it to Gpio 4

const uint16_t kIrLed = 4;  // ESP GPIO pin to use. Recommended: 4 (D2).
IRsend irsend(kIrLed);

5) Send the Html Web Page to Server. Index_html is the root page of the server.

void handleRoot() {
  server.send(200, "text/html",index_html);
}

6) This Function is made to handle request from the Root page. There are 4 buttons on Html Web Page. Each button makes a separate request to control the Ac. According to those request IR Signal is sent to the Ac. The rawData will change according to your remote’s reading.

void handleIr(){
for (uint8_t i = 0; i < server.args(); i++) {
    if (server.argName(i) == "on") {
      temp="24";
    uint16_t rawData[179] = {3198, 1576,  412, 382,  410, 1156,  430, 366,  428, 366,  426, 1166,  422, 360,  432, 1166,  418, 376,  416, 382,  412, 1156,  430, 1174,  410, 1176,  412, 380,  414, 1154,  430, 354,  438, 1176,  412, 1154,  432, 1160,  426, 366,  428, 384,  410, 362,  428, 362,  430, 1148,  440, 1176,  408, 382,  414, 1160,  424, 1174,  430, 342,  434, 380,  412, 1174,  412, 362,  430, 382,  412, 1178,  410, 360,  432, 358,  434, 1174,  412, 1174,  412, 372,  422, 1168,  416, 1178,  410, 1174,  412, 1178,  408, 1176,  410, 382,  412, 1178,  408, 1174,  412, 1176,  410, 1158,  430, 382,  408, 382,  412, 376,  416, 1176,  412, 380,  412, 362,  430, 380,  412, 382,  412, 1180,  406, 1174,  410, 1176,  412, 382,  412, 380,  412, 1176,  412, 380,  412, 1178,  410, 384,  408, 366,  424, 372,  424, 1164,  420, 1176,  412, 380,  412, 1154,  434, 380,  412, 382,  410, 1162,  426, 1164,  420, 380,  410, 384,  408, 1176,  412, 372,  420, 382,  412, 1176,  412, 384,  408, 366,  428, 1174,  414, 1178,  408, 366,  426, 1156,  430, 1178,  408};  // MITSUBISHI_HEAVY_88uint16_t rawData[179] = {3198, 1576,  412, 382,  410, 1156,  430, 366,  428, 366,  426, 1166,  422, 360,  432, 1166,  418, 376,  416, 382,  412, 1156,  430, 1174,  410, 1176,  412, 380,  414, 1154,  430, 354,  438, 1176,  412, 1154,  432, 1160,  426, 366,  428, 384,  410, 362,  428, 362,  430, 1148,  440, 1176,  408, 382,  414, 1160,  424, 1174,  430, 342,  434, 380,  412, 1174,  412, 362,  430, 382,  412, 1178,  410, 360,  432, 358,  434, 1174,  412, 1174,  412, 372,  422, 1168,  416, 1178,  410, 1174,  412, 1178,  408, 1176,  410, 382,  412, 1178,  408, 1174,  412, 1176,  410, 1158,  430, 382,  408, 382,  412, 376,  416, 1176,  412, 380,  412, 362,  430, 380,  412, 382,  412, 1180,  406, 1174,  410, 1176,  412, 382,  412, 380,  412, 1176,  412, 380,  412, 1178,  410, 384,  408, 366,  424, 372,  424, 1164,  420, 1176,  412, 380,  412, 1154,  434, 380,  412, 382,  410, 1162,  426, 1164,  420, 380,  410, 384,  408, 1176,  412, 372,  420, 382,  412, 1176,  412, 384,  408, 366,  428, 1174,  414, 1178,  408, 366,  426, 1156,  430, 1178,  408};  // MITSUBISHI_HEAVY_88
    Serial.println("Turning the Ac on/off");
    irsend.sendRaw(rawData, 179, 38);  // Send a raw data capture at 38kHz.
    }
    else if(server.argName(i) == "off") {
      temp="";
   uint16_t rawData[179] = {3170, 1556,  434, 364,  426, 1176,  414, 368,  424, 380,  414, 1156,  430, 380,  412, 1176,  412, 380,  414, 370,  422, 1152,  436, 1162,  426, 1172,  412, 364,  430, 1156,  434, 362,  426, 1176,  414, 1156,  430, 1174,  412, 368,  422, 374,  420, 358,  434, 382,  410, 1176,  412, 1176,  410, 384,  408, 1160,  426, 1162,  426, 384,  408, 368,  424, 1156,  432, 366,  426, 382,  412, 1174,  414, 380,  410, 364,  430, 1174,  410, 1176,  410, 368,  424, 1176,  412, 1176,  412, 1158,  428, 1160,  426, 1176,  412, 364,  426, 1154,  432, 1176,  414, 1154,  432, 1160,  426, 384,  408, 382,  410, 386,  410, 1174,  412, 380,  410, 366,  428, 366,  428, 380,  412, 1160,  428, 1172,  412, 1176,  414, 372,  420, 366,  424, 1162,  426, 384,  408, 1176,  412, 378,  414, 362,  430, 384,  410, 1176,  412, 1176,  410, 382,  410, 1176,  412, 380,  412, 382,  412, 1174,  414, 1162,  422, 1176,  412, 368,  424, 1158,  428, 366,  426, 384,  410, 1164,  424, 382,  410, 368,  426, 382,  412, 1176,  412, 380,  412, 1166,  422, 1176,  412};  
    Serial.println("Turning the Ac off");
    irsend.sendRaw(rawData, 179, 38);  // Send a raw data capture at 38kHz.
    }
    else if(server.argName(i) == "18") {
         temp="18";  
   uint16_t rawData[179] = {3188, 1538,  450, 362,  432, 1172,  414, 378,  412, 360,  434, 1172,  414, 378,  414, 1172,  414, 380,  412, 366,  428, 1170,  414, 1176,  412, 1148,  440, 366,  424, 1158,  430, 380,  412, 1148,  440, 1156,  426, 1176,  412, 360,  434, 380,  412, 382,  410, 366,  426, 1172,  416, 1174,  410, 334,  460, 1156,  430, 1174,  414, 366,  426, 364,  426, 1152,  434, 382,  414, 380,  412, 1150,  436, 360,  432, 362,  430, 1176,  410, 1174,  414, 366,  426, 1172,  416, 1172,  412, 1160,  426, 368,  424, 1180,  408, 382,  412, 1150,  434, 1178,  410, 1174,  412, 1152,  434, 384,  408, 1174,  412, 380,  412, 1156,  430, 368,  426, 380,  412, 380,  414, 380,  412, 1156,  430, 1156,  430, 1178,  412, 380,  414, 362,  430, 1174,  412, 368,  422, 1176,  414, 380,  412, 382,  410, 362,  432, 1178,  410, 1172,  412, 366,  426, 1174,  412, 366,  426, 380,  412, 1174,  412, 1164,  424, 380,  414, 380,  412, 1172,  414, 1174,  410, 1176,  410, 1176,  412, 364,  430, 380,  412, 1176,  412, 1172,  414, 368,  424, 382,  412, 362,  430};  // MITSUBISHI_HEAVY_88
   Serial.println("Turning the tepmerature to 18");
   irsend.sendRaw(rawData, 179, 38);  // Send a raw data capture at 38kHz.
    }
    else if(server.argName(i) == "19") {
         temp="19";
   uint16_t rawData[179] = {3176, 1572,  412, 370,  422, 1172,  414, 372,  422, 356,  436, 1172,  414, 378,  414, 1154,  432, 366,  428, 366,  426, 1146,  440, 1156,  430, 1156,  430, 358,  434, 1154,  432, 366,  428, 1174,  412, 1154,  432, 1158,  428, 372,  420, 380,  414, 380,  410, 382,  414, 1150,  432, 1174,  414, 382,  410, 1160,  426, 1164,  424, 378,  414, 366,  426, 1156,  430, 360,  432, 380,  412, 1174,  414, 378,  414, 362,  430, 1170,  414, 1172,  416, 382,  410, 1160,  426, 1154,  432, 1172,  416, 366,  426, 1156,  430, 382,  410, 1172,  416, 1150,  434, 1172,  414, 1172,  414, 378,  416, 1156,  428, 378,  416, 1172,  414, 378,  414, 366,  428, 376,  414, 364,  430, 1174,  410, 1156,  430, 1174,  414, 380,  414, 380,  412, 1156,  430, 380,  412, 1160,  426, 380,  414, 380,  412, 382,  412, 1156,  430, 1172,  416, 378,  414, 1158,  428, 378,  412, 380,  412, 1174,  416, 1156,  426, 372,  422, 1174,  412, 378,  414, 1174,  410, 1170,  418, 1174,  410, 384,  410, 380,  414, 1158,  428, 380,  412, 1166,  420, 366,  428, 366,  426};  // MITSUBISHI_HEAVY_88
    Serial.println("Turning the temperature to 19 ");
   irsend.sendRaw(rawData, 179, 38);  // Send a raw data capture at 38kHz.
    }

     else if(server.argName(i) == "20") {
      temp="20";
   uint16_t rawData[179] = {3172, 1564,  428, 352,  434, 1178,  412, 364,  430, 378,  412, 1162,  426, 364,  426, 1182,  408, 368,  424, 368,  424, 1166,  422, 1174,  412, 1152,  434, 354,  438, 1178,  410, 364,  426, 1176,  412, 1162,  426, 1174,  412, 382,  410, 366,  426, 380,  412, 368,  426, 1174,  412, 1162,  426, 368,  426, 1162,  422, 1178,  410, 380,  412, 370,  424, 1156,  432, 380,  410, 382,  412, 1178,  408, 362,  432, 362,  432, 1172,  414, 1160,  426, 376,  416, 1160,  426, 1176,  412, 1152,  434, 374,  416, 1174,  414, 382,  410, 1178,  410, 1154,  432, 1162,  424, 1148,  438, 366,  428, 1156,  430, 382,  410, 1156,  432, 380,  412, 362,  432, 386,  406, 382,  412, 1174,  412, 1174,  412, 1176,  410, 382,  412, 380,  410, 1176,  412, 382,  410, 1176,  412, 360,  430, 368,  428, 382,  408, 1176,  412, 1176,  412, 366,  424, 1174,  412, 382,  410, 386,  410, 1174,  412, 1162,  424, 366,  428, 382,  410, 382,  414, 1154,  432, 1156,  432, 1174,  410, 364,  428, 368,  422, 1164,  422, 1158,  432, 1160,  426, 382,  412, 382,  408};  // MITSUBISHI_HEAVY_88
    Serial.println("Turning the temperature to 20 ");
   irsend.sendRaw(rawData, 179, 38);  // Send a raw data capture at 38kHz.
    }

     else if(server.argName(i) == "21") {
    temp="21";
   uint16_t rawData[179] = {3188, 1576,  418, 372,  414, 1176,  416, 374,  416, 376,  416, 1152,  440, 360,  430, 1172,  418, 376,  414, 376,  416, 1156,  432, 1170,  416, 1170,  416, 374,  414, 1152,  436, 376,  414, 1172,  418, 1152,  434, 1168,  418, 378,  412, 358,  434, 362,  432, 378,  414, 1176,  416, 1170,  416, 362,  426, 1174,  418, 1170,  416, 374,  416, 378,  412, 1158,  434, 374,  414, 360,  434, 1158,  434, 360,  430, 368,  422, 1176,  414, 1170,  418, 356,  432, 1176,  416, 1170,  416, 1172,  414, 360,  428, 1172,  416, 376,  412, 1160,  434, 1168,  418, 1168,  418, 1168,  420, 360,  428, 1172,  418, 376,  414, 1170,  420, 374,  416, 376,  416, 380,  414, 380,  414, 1174,  416, 1160,  426, 1172,  416, 374,  414, 378,  414, 1158,  432, 374,  416, 1174,  402, 386,  406, 386,  410, 382,  410, 1182,  402, 1182,  404, 386,  414, 1176,  402, 390,  408, 386,  406, 1176,  406, 1180,  408, 388,  402, 1186,  402, 1180,  408, 388,  404, 1184,  402, 1180,  406, 388,  408, 384,  408, 1186,  400, 390,  404, 384,  414, 1178,  402, 388,  404};  // MITSUBISHI_HEAVY_88
    Serial.println("Turning the temperature to 21");
   irsend.sendRaw(rawData, 179, 38);  // Send a raw data capture at 38kHz.
    }

     else if(server.argName(i) == "22") {
         temp="22";
   uint16_t rawData[179] = {3186, 1560,  426, 380,  412, 1162,  426, 366,  424, 380,  412, 1178,  410, 384,  406, 1156,  430, 364,  428, 380,  412, 1156,  430, 1152,  432, 1182,  408, 378,  412, 1174,  414, 362,  428, 1178,  410, 1174,  416, 1156,  430, 380,  412, 368,  426, 364,  430, 382,  410, 1156,  428, 1160,  428, 386,  406, 1174,  414, 1162,  422, 386,  408, 382,  412, 1174,  412, 360,  434, 384,  406, 1176,  410, 382,  410, 382,  412, 1176,  412, 1174,  412, 370,  422, 1158,  430, 1154,  428, 1178,  410, 366,  424, 1156,  434, 364,  424, 1160,  428, 1176,  412, 1174,  414, 1172,  412, 382,  412, 1160,  428, 366,  424, 1176,  412, 382,  410, 380,  414, 364,  428, 372,  420, 1182,  410, 1178,  408, 1168,  420, 366,  424, 382,  410, 1176,  410, 380,  412, 1168,  418, 382,  412, 364,  426, 388,  406, 1176,  412, 1176,  408, 388,  404, 1178,  412, 382,  410, 382,  410, 1184,  404, 1178,  414, 376,  412, 386,  406, 1182,  404, 384,  410, 1178,  408, 1180,  406, 384,  408, 388,  408, 1174,  410, 1180,  408, 384,  406, 1178,  410, 382,  410};  // MITSUBISHI_HEAVY_88
    Serial.println("Turning the temperature to 22");
   irsend.sendRaw(rawData, 179, 38);  // Send a raw data capture at 38kHz.
    }

     else if(server.argName(i) == "23") {
          temp="23";
       uint16_t rawData[179] = {3196, 1548,  450, 342,  446, 1160,  430, 364,  428, 366,  422, 1150,  444, 348,  442, 1158,  430, 364,  426, 366,  422, 1166,  428, 1156,  428, 1142,  444, 348,  444, 1148,  442, 348,  442, 1160,  428, 1138,  448, 1144,  442, 368,  424, 370,  420, 372,  420, 372,  424, 1162,  428, 1158,  426, 366,  426, 1140,  452, 1142,  442, 348,  444, 370,  420, 1166,  428, 344,  444, 368,  422, 1164,  428, 366,  424, 364,  424, 1164,  430, 1156,  426, 370,  422, 1140,  450, 1158,  428, 1158,  428, 344,  448, 1160,  428, 352,  442, 1158,  428, 1140,  442, 1164,  424, 1164,  424, 368,  424, 1160,  428, 368,  426, 1162,  426, 366,  426, 350,  438, 354,  440, 354,  440, 1164,  428, 1156,  428, 1158,  428, 354,  438, 370,  420, 1166,  414, 378,  408, 1182,  410, 382,  404, 384,  412, 380,  414, 1176,  412, 1178,  408, 384,  406, 1178,  412, 378,  410, 382,  410, 1178,  412, 1174,  412, 380,  408, 1184,  410, 384,  404, 388,  408, 1176,  414, 1178,  408, 382,  408, 384,  408, 1180,  410, 382,  406, 1184,  408, 1172,  414, 382,  410};  // MITSUBISHI_HEAVY_88
    Serial.println("Turning the temperature to 23");
   irsend.sendRaw(rawData, 179, 38);  // Send a raw data capture at 38kHz.
    }

     else if(server.argName(i) == "24") {
      temp="24";
   uint16_t rawData[179] = {3196, 1554,  432, 380,  414, 1156,  432, 380,  412, 366,  428, 1158,  428, 380,  412, 1176,  410, 360,  430, 358,  436, 1154,  432, 1150,  434, 1156,  432, 356,  434, 1176,  414, 380,  410, 1168,  418, 1176,  412, 1174,  412, 380,  412, 384,  410, 362,  428, 366,  430, 1172,  414, 1148,  436, 366,  428, 1152,  430, 1176,  412, 384,  408, 360,  432, 1176,  410, 382,  412, 380,  414, 1174,  412, 376,  420, 380,  410, 1178,  410, 1154,  432, 364,  430, 1174,  414, 1172,  412, 1174,  412, 370,  422, 1176,  414, 380,  412, 1174,  412, 1174,  412, 1174,  412, 1154,  434, 360,  430, 1176,  412, 382,  414, 1156,  432, 358,  430, 368,  428, 382,  410, 368,  426, 1146,  440, 1174,  412, 1176,  412, 360,  432, 368,  424, 1178,  410, 364,  430, 1174,  410, 384,  410, 366,  426, 386,  408, 1174,  414, 1154,  430, 362,  432, 1176,  410, 380,  412, 382,  412, 1160,  428, 1174,  412, 382,  410, 384,  408, 382,  412, 380,  412, 1176,  410, 1176,  412, 386,  406, 360,  432, 1156,  430, 1178,  410, 1156,  430, 1174,  412, 382,  410};  // MITSUBISHI_HEAVY_88
    Serial.println("Turning the temperature to 24 ");
   irsend.sendRaw(rawData, 179, 38);  // Send a raw data capture at 38kHz.
    }

     else if(server.argName(i) == "25") {
         temp="25";
   uint16_t rawData[179] = {3206, 1540,  452, 366,  432, 1152,  426, 368,  432, 332,  456, 1160,  426, 358,  438, 1142,  438, 342,  456, 356,  434, 1158,  424, 1162,  424, 1142,  444, 368,  430, 1156,  422, 370,  430, 1156,  424, 1164,  424, 1162,  424, 350,  448, 336,  454, 352,  440, 346,  446, 1160,  422, 1168,  420, 354,  446, 1140,  440, 1164,  420, 352,  450, 362,  428, 1146,  436, 372,  430, 346,  446, 1130,  450, 372,  428, 338,  450, 1166,  414, 1168,  418, 350,  452, 1158,  422, 1166,  416, 1152,  434, 348,  456, 1160,  414, 364,  438, 1136,  442, 1172,  414, 1166,  418, 1154,  432, 362,  442, 1160,  416, 378,  424, 1144,  432, 354,  448, 368,  424, 370,  422, 372,  420, 1140,  442, 1158,  426, 1172,  416, 376,  426, 342,  444, 1196,  392, 392,  396, 1174,  420, 370,  418, 378,  412, 380,  416, 1174,  420, 1168,  420, 370,  416, 1174,  420, 370,  414, 378,  416, 1172,  422, 1166,  422, 370,  418, 1170,  422, 1164,  420, 1184,  404, 368,  418, 1172,  420, 372,  414, 378,  414, 1182,  414, 372,  416, 376,  414, 378,  414, 1180,  414};  // MITSUBISHI_HEAVY_88
    Serial.println("Turning the temperature to 25");
   irsend.sendRaw(rawData, 179, 38);  // Send a raw data capture at 38kHz.
    }

     else if(server.argName(i) == "26") {
         temp="26";
   uint16_t rawData[179] = {3194, 1574,  424, 370,  412, 1172,  422, 368,  418, 378,  416, 1172,  420, 348,  438, 1168,  424, 354,  434, 374,  418, 1152,  442, 1142,  444, 1162,  426, 366,  420, 1168,  424, 368,  420, 1166,  428, 1160,  426, 1146,  438, 368,  420, 374,  416, 376,  418, 372,  422, 1152,  440, 1160,  426, 368,  420, 1166,  426, 1160,  428, 368,  420, 372,  418, 1152,  440, 368,  418, 372,  420, 1168,  426, 368,  420, 372,  420, 1150,  440, 1164,  424, 366,  420, 1158,  436, 1162,  424, 1162,  426, 366,  420, 1164,  428, 370,  418, 1168,  424, 1162,  424, 1148,  440, 1162,  426, 368,  420, 1150,  442, 356,  432, 1170,  420, 350,  438, 370,  422, 358,  434, 364,  428, 1170,  424, 1160,  428, 1160,  428, 366,  418, 374,  418, 1168,  406, 384,  410, 1182,  404, 388,  406, 388,  402, 386,  406, 1182,  406, 1186,  402, 386,  406, 1180,  408, 386,  408, 386,  404, 1182,  404, 1180,  408, 388,  410, 382,  404, 1182,  404, 1186,  404, 388,  404, 1184,  402, 390,  406, 380,  410, 1180,  404, 1182,  404, 384,  412, 382,  408, 1180,  408};  // MITSUBISHI_HEAVY_88
    Serial.println("Turning the temperature to 26");
   irsend.sendRaw(rawData, 179, 38);  // Send a raw data capture at 38kHz.
    }

     else if(server.argName(i) == "27") {
         temp="27";
   uint16_t rawData[179] = {3190, 1566,  420, 356,  436, 1174,  414, 362,  428, 364,  430, 1152,  434, 380,  414, 1158,  428, 356,  438, 368,  422, 1162,  424, 1174,  412, 1160,  426, 364,  430, 1162,  424, 384,  410, 1150,  436, 1172,  414, 1174,  412, 380,  414, 356,  436, 364,  428, 368,  426, 1178,  410, 1174,  412, 366,  426, 1176,  410, 1176,  412, 362,  428, 382,  410, 1156,  434, 382,  410, 382,  412, 1156,  430, 380,  410, 384,  410, 1162,  428, 1156,  430, 382,  408, 1176,  412, 1176,  410, 1158,  428, 380,  414, 1182,  402, 382,  412, 1154,  432, 1176,  412, 1174,  412, 1162,  424, 380,  414, 1174,  410, 382,  410, 1176,  412, 382,  410, 368,  424, 384,  412, 380,  412, 1158,  428, 1174,  412, 1176,  414, 362,  430, 362,  428, 1164,  424, 382,  408, 1176,  412, 368,  424, 382,  410, 384,  408, 1178,  412, 1174,  412, 368,  424, 1180,  408, 382,  410, 382,  410, 1154,  434, 1176,  408, 390,  406, 1156,  430, 368,  424, 1178,  410, 382,  410, 1182,  404, 368,  424, 386,  406, 1180,  408, 382,  410, 1158,  430, 360,  430, 1182,  406};  // MITSUBISHI_HEAVY_88
    Serial.println("Turning the temperature to 27");
   irsend.sendRaw(rawData, 179, 38);  // Send a raw data capture at 38kHz.
    }

     else if(server.argName(i) == "28") {
         temp="28";
   uint16_t rawData[179] = {3170, 1554,  438, 356,  432, 1176,  416, 378,  412, 380,  412, 1174,  414, 364,  426, 1158,  432, 374,  414, 364,  430, 1172,  418, 1170,  414, 1172,  416, 362,  428, 1174,  412, 382,  408, 1174,  416, 1170,  418, 1172,  412, 382,  408, 380,  412, 384,  408, 360,  432, 1174,  416, 1176,  410, 354,  436, 1156,  432, 1176,  412, 374,  416, 380,  412, 1158,  430, 378,  414, 382,  410, 1176,  412, 370,  420, 364,  430, 1174,  416, 1174,  412, 376,  416, 1170,  416, 1176,  412, 1172,  416, 350,  438, 1174,  414, 382,  412, 1174,  414, 1174,  414, 1172,  412, 1172,  414, 378,  416, 1172,  416, 378,  412, 1174,  416, 368,  420, 362,  430, 364,  428, 380,  414, 1174,  406, 1180,  408, 1184,  402, 390,  406, 382,  412, 1180,  404, 386,  410, 1178,  404, 386,  410, 382,  412, 382,  410, 1180,  402, 1180,  406, 372,  424, 1178,  406, 386,  412, 382,  410, 1178,  406, 1180,  408, 388,  408, 382,  408, 382,  410, 1178,  410, 386,  406, 1182,  402, 390,  410, 382,  408, 1178,  408, 1182,  402, 1180,  408, 386,  412, 1178,  402};  // MITSUBISHI_HEAVY_88
    Serial.println("Turning the temperature to 28");
   irsend.sendRaw(rawData, 179, 38);  // Send a raw data capture at 38kHz.
    }

     else if(server.argName(i) == "29") {
         temp="29";
   uint16_t rawData[179] = {3194, 1564,  432, 356,  430, 1174,  418, 376,  412, 362,  428, 1176,  418, 374,  412, 1170,  420, 374,  414, 380,  414, 1172,  418, 1172,  414, 1150,  436, 370,  418, 1168,  422, 372,  414, 1170,  422, 1158,  428, 1168,  420, 362,  420, 382,  416, 362,  430, 376,  416, 1172,  418, 1158,  428, 370,  416, 1174,  418, 1170,  416, 350,  438, 362,  432, 1172,  418, 376,  414, 374,  416, 1160,  428, 356,  432, 382,  412, 1172,  418, 1152,  434, 372,  418, 1170,  420, 1168,  420, 1152,  434, 372,  418, 1174,  416, 352,  436, 1170,  420, 1168,  418, 1168,  420, 1144,  442, 374,  414, 1172,  418, 372,  418, 1172,  418, 374,  414, 380,  414, 378,  414, 378,  406, 1182,  406, 1184,  402, 1178,  412, 380,  412, 382,  408, 1180,  404, 388,  404, 1182,  406, 384,  408, 384,  410, 386,  406, 1178,  410, 1178,  408, 386,  404, 1184,  406, 386,  404, 392,  406, 1176,  408, 1180,  410, 380,  406, 1178,  410, 1178,  410, 384,  404, 388,  404, 1182,  410, 382,  406, 390,  402, 1182,  410, 384,  406, 384,  410, 1178,  410, 1180,  414};  // MITSUBISHI_HEAVY_88
    Serial.println("Turning the temperature to 29");
   irsend.sendRaw(rawData, 179, 38);  // Send a raw data capture at 38kHz.
    }

     else if(server.argName(i) == "30") {
          temp="30";
   uint16_t rawData[179] = {3200, 1548,  446, 370,  416, 1154,  442, 350,  436, 348,  444, 1168,  426, 368,  420, 1166,  426, 370,  418, 350,  440, 1168,  426, 1162,  426, 1160,  424, 366,  420, 1166,  426, 350,  436, 1150,  442, 1162,  424, 1160,  426, 360,  426, 374,  418, 366,  428, 372,  420, 1168,  424, 1144,  442, 366,  420, 1168,  424, 1160,  426, 350,  438, 370,  420, 1172,  420, 368,  420, 372,  420, 1166,  426, 370,  420, 374,  420, 1166,  426, 1160,  426, 368,  418, 1170,  424, 1144,  442, 1142,  446, 364,  424, 1168,  422, 350,  436, 1168,  426, 1164,  422, 1162,  424, 1164,  422, 372,  416, 1170,  422, 352,  436, 1170,  420, 370,  416, 376,  408, 388,  416, 370,  414, 1178,  408, 1178,  410, 1176,  410, 380,  420, 374,  408, 1182,  408, 384,  408, 1180,  412, 380,  410, 382,  406, 390,  404, 1182,  410, 1176,  408, 380,  412, 1180,  410, 380,  408, 384,  406, 1186,  410, 1174,  408, 382,  408, 384,  406, 1184,  418, 376,  404, 386,  406, 1182,  416, 374,  408, 388,  402, 1186,  414, 1170,  418, 372,  406, 1186,  410, 1176,  414};  // MITSUBISHI_HEAVY_88
    Serial.println("Turning the temperature to 30");
   irsend.sendRaw(rawData, 179, 38);  // Send a raw data capture at 38kHz.
    }
    
   }  //Load the Root Page again 
      handleRoot(); }  //At the end again the Root Page is loaded

7) After the Root Page is Loaded we have to Update the Information on the Root Page So these function is made to route the Ac temperature Value to the Root Page .

void handledisplay(){
     //Send the request to change the temperature on web page again.
    server.send(200, "text/plane", temp);
    }

8) These Fuction is made to handle the wrong request from the webpage.

void handleNotFound() {
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i = 0; i < server.args(); i++)
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  server.send(404, "text/plain", message);
}

Calling the Function in Setup

server.onNotFound(handleNotFound);

9) Starting the Serial Moniter, Initializing the IRLed and configuring the Wi-Fi.

irsend.begin();
Serial.begin(115200);
WiFi.begin(kSsid, kPassword);

10) Connecting to Wifi.

while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(kSsid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

11) Making the routes for Esp8266 Server.

server.on("/", handleRoot);
server.on("/ir", handleIr);
server.on("/readtemp", handledisplay);

12) Start the Server

server.begin();

13) Initialize the Server to handle Client Requests

void loop(void) {
 delay(100);
server.handleClient();
}

HTML Sketch
1) Include the Html and Javascript in Program Memory

const char index_html[] PROGMEM = R"rawliteral(
//Html Coode
)rawliteral";

2) Design of the webpage

<head>
<style>
 body {
      min-width: 200px;
      max-width: 800px;
      height: 400px;
      margin: 0 auto;
    }
.button {
  background-color: #0000; /* Green */
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 24px;
  margin: 4px 2px;
  cursor: pointer;
 
  }
.button2 {background-color: #f44336;border-radius: 10%;width: 100px;} /* red */
.button3 {background-color: #008CBA;border-radius: 10%;width: 100px;} /* blue */ 
.button4 {background-color: limegreen;border-radius: 10%;width:100px;}  /* green*/
.button5 {background-color: #213346;border-radius: 10%;width: 100px;} /* Black */
.triangle-up {
  width: 0;
  height: 0;
  border-left: 15px solid transparent;
  border-right: 15px solid transparent;
  border-bottom: 30px solid #ffe;
  margin-left:10%;
}
.triangle-down {
  width: 0;
  height: 0;
  border-left: 15px solid transparent;
  border-right: 15px solid transparent;
  border-top: 30px solid #ffe;
  margin-left:10%;
  }
.buttongroup {
    margin-left:50px;
  margin-top:50px;
  
}
.grid-container {
  display: grid;
  grid-template-columns: auto auto auto;
  padding: 20px;
  margin-left:-10%;
  width: 300px;
}
input[type=text] {
  width: 25%;
  padding: 30px ;
  box-sizing: border-box;
  border: 2px solid blue;
  border-radius: 10px;
  height:50px;
  font-size:28pt;
}
.tvalue{
margin-left:180px;
margin-top:30px;
}
.image{
margin-top:50px;
}
</style>
</head>
<body>
<div class="logoimage">
<img src = “Image Address”  width = "500" height = "180" >
</div>
<div class="grid-container">
<div class="image">
<img src ="https://images-na.ssl-images-amazon.com/images/I/316Zg2OYrXL.jpg" height="120" width="450" margin-top="5px"> <!-- image-->
<input type ="text" id="temperatureshowdisplay" class="tvalue"/>
</div>
<div class=buttongroup>
<a   href="#" id="tempupHref"><button  onclick=tempup() class="button button2"><div class="triangle-up"></div></button></a><br><br>
<a href="ir?on"><button class="button button3">ON</button></a><br><br>
<a href="ir?off"><button class="button button4">OFF</button></a><br><br>
<a   href="#" id="tempdownHref"><button onclick=tempdown() class="button button5"><div class="triangle-down"></div></button></a>
<input hidden type ="text" id="temperaturedisplay" class="tvalue" value="24"/>
</div>
</div>
</body>

3) Javascript to Update the root page and hide certain details from the user.
These Function called when we have to increase the Ac Temperature

<script>
  function tempup(){
   var temp;
   var temps;
   var str="ir?"
   temp = parseFloat(document.getElementById("temperaturedisplay").value);
   temp=temp+1;
   if(temp>=31){
    temp=30;
   }
   temps=temp.toString();
    document.getElementById("tempupHref").href = str.concat(temps);
   }

These function is called when we have to decrease the Temperature.

function tempdown(){
    var temp;
   var temps;
   var str="ir?"
   temp = parseFloat(document.getElementById("temperaturedisplay").value);
   temp=temp-1;
   if(temp<=17){
    temp=18;  }
   temps=temp.toString();
   document.getElementById("tempdownHref").href = str.concat(temps);
    }

Set Interval Function to Update the Temperature value on root Page.

setInterval(function() {
     var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        document.getElementById("temperatureshowdisplay").value =
        this.responseText;
        document.getElementById("temperaturedisplay").value =
        this.responseText;
         }
    };
     xhttp.open("GET", "readtemp", true);
     xhttp.send();
   }, 1000);
</script>

Note : On the Web Server when client Request is made we read these request arguments, According to it temperature value gets updated and we are brought back to the root page as we call the handleroot fuction. On our Root page the default temperature value is 24. In oder to update it we have included the script which makes the request for updated temperature value.

However these updation of value takes 1 sec and thus user is able to see the default value changing to updated value which is not a good view. So we have included two text boxes. The first text box from which we read the value and update it is hidden from the user and while the other text box having no default value on root page is assigned the same value as in our hidden text box on updation. Thus at the time of updation user see a blank text box for 1 seconds instead of default value.

OUTPUT

If you are still facing issue regarding Controlling AC through Web Server using ESP8266 Feel free to Ask Doubts in the Comment Box Below and Don’t Forget to Follow us on 👍 Social Networks😉 Happy Splunking >