WIFI SMART HOME || ESP8266 NODE MCU HOME AUTOMATION

CIRCUIT:-


CODE:-

#include <ESP8266WiFi.h>

const char WiFiPassword[] = "mkinventions";

const char AP_NameChar[] = "WIFI SMART HOME" ;

 

WiFiServer server(80);


String request = "";

int LIGHT1 = D0;

int LIGHT2 = D1;

int LIGHT3 = D2;

int LIGHT4 = D3;

 

void setup() 

{

    pinMode(LIGHT1, OUTPUT);

    pinMode(LIGHT2, OUTPUT); 

    pinMode(LIGHT3, OUTPUT); 

    pinMode(LIGHT4, OUTPUT); 

     

    boolean conn = WiFi.softAP(AP_NameChar, WiFiPassword);

    server.begin(); 

} // void setup()

 

 

void loop() 

{

     // Check if a client has connected

    WiFiClient client = server.available();

    if (!client)  {  return;  }

 

    // Read the first line of the request

    request = client.readStringUntil('\r');

 

    if       ( request.indexOf("LIGHT1ON") > 0 )  { digitalWrite(LIGHT1, HIGH);  }

    else if  ( request.indexOf("LIGHT1OFF") > 0 ) { digitalWrite(LIGHT1, LOW);   }


    if       ( request.indexOf("LIGHT2ON") > 0 )  { digitalWrite(LIGHT2, HIGH);  }

    else if  ( request.indexOf("LIGHT2OFF") > 0 ) { digitalWrite(LIGHT2, LOW);   }


    if       ( request.indexOf("LIGHT3ON") > 0 )  { digitalWrite(LIGHT3, HIGH);  }

    else if  ( request.indexOf("LIGHT3OFF") > 0 ) { digitalWrite(LIGHT3, LOW);   }

            

    if       ( request.indexOf("LIGHT4ON") > 0 )  { digitalWrite(LIGHT4, HIGH);  }

    else if  ( request.indexOf("LIGHT4OFF") > 0 ) { digitalWrite(LIGHT4, LOW);   }    

     

     client.flush();

 } // void loop()

Post a Comment

0 Comments