ESP8266 Soft Access Point Automation

Arduino sketch for controlling 4 relay with esp8266 WIFI Access point mode 


 #include <ESP8266WiFi.h>

WiFiClient client;

WiFiServer server(80);


#define load1 D5

#define load2 D6

#define load3 D7

#define load4 D8

void setup() 

{

  Serial.begin(9600);

  WiFi.softAP("WIFI Power Switch", "123456789");

  Serial.println();

  Serial.println("NodeMCU Started!");

  Serial.println(WiFi.softAPIP());

  server.begin();

  pinMode(load1, OUTPUT);

  pinMode(load2, OUTPUT);

  pinMode(load3, OUTPUT);

  pinMode(load4, OUTPUT);

}


void loop() 

  {

  client = server.available();  //Gets a client that is connected to the server and has data available for reading.    

  if (client == 1)

  {  

    String request =  client.readStringUntil('\n');

    Serial.println(request);

    request.trim();

    if(request == "GET /load1on HTTP/1.1")

    {

      digitalWrite(load1, HIGH);

    }

    if(request == "GET /load1off HTTP/1.1")

    {

      digitalWrite(load1, LOW);

    }

      if(request == "GET /load2on HTTP/1.1")

    {

      digitalWrite(load2, HIGH);

    }

    if(request == "GET /load2off HTTP/1.1")

    {

      digitalWrite(load2, LOW);

    }

      if(request == "GET /load3on HTTP/1.1")

    {

      digitalWrite(load3, HIGH);

    }

    if(request == "GET /load3off HTTP/1.1")

    {

      digitalWrite(load3, LOW);

    }

      if(request == "GET /load4on HTTP/1.1")

    {

      digitalWrite(load4, HIGH);

    }

    if(request == "GET /load4off HTTP/1.1")

    {

      digitalWrite(load4, LOW);

    }    }    }

  

  

Comments

Popular posts from this blog

4 Stage Timer With DS3231RTC Module.

Interfacing KY038 sound sensor with Raspberry pi Pico

Interfacing MQ2 Gas & Smoke Sensor With Raspberry Pi Pico