ESP8266 whatsapp IOT project with 2 relays

 //#include <WiFi.h>

#include <ESP8266WiFi.h>

#include <ThingESP.h>


ThingESP8266 thing("surya33319", "suryaproject", "automation");


int LIGHT = D2;

int FAN = D3;


unsigned long previousMillis = 0;   //G.S Entertaiments

const long INTERVAL = 6000;  


void setup()

{

  Serial.begin(115200);

  pinMode(LIGHT, OUTPUT);

  Serial.begin(115200);

  pinMode(FAN, OUTPUT);

  thing.SetWiFi("surya internet", "surya33333");

  thing.initDevice();

}



String HandleResponse(String query)

{

 if (query == "light on") {

    digitalWrite(LIGHT, 1);

    return "Done: Light Turned ON";

  }


  else if (query == "light off") {

    digitalWrite(LIGHT, 0);

    return "Done: Light Turned OFF";

  }


  else if (query == "light status")

    return digitalRead(LIGHT) ? "LIGHT is OFF" : "LIGHT is ON";

  else return "Your query was invalid..";


  if (query == "fan on") {

    digitalWrite(FAN, 1);

    return "Done: Fan Turned ON";

  }


  else if (query == "fan off") {

    digitalWrite(FAN, 0);

    return "Done: Fan Turned OFF";

  }


  else if (query == "fan status")

    return digitalRead(FAN) ? "FAN is OFF" : "FAN is ON";

  else return "Your query was invalid..";



}



void loop()

{

  thing.Handle();


}


Comments