group-icon
Arduino + Raspberry Pi Lovers
Discussion and Q&A about Arduino and Raspberry Pi projects.
194 Members
Join this group to post and comment.
Kunal Gokhe
Kunal Gokhe
Mechanical
08 Feb 2019

Create ESP8266 Web Server

Create ESP8266 web server using Arduino IDE. Learn about connecting it to Wi-Fi and creating a web server using a sample text containing web page. 

Step 1: Circuit Time

Make a circuit as per the programming ESP8266 with Arduino Board.

Step 2: Code Time

This is code for Creating ESP8266 web server. First, we initialized server at port 80 and two constants for Wi-Fi SSID and Password. In setup, Serial started at 115200 baud to check the status of ESP8266. Wi-Fi begins to connect with SSID and Password and waited till it connects to the Wi-Fi. Print the Local IP to Serial monitor to use that address as Web server address. Created an index page with the text “Hello! This is an index page.” using the server.on and server.send as you can see in code. And at last, Begin the Server. In loop, server.handleClient() is used for Handling incoming client requests

Step 3: Upload code to ESP8266

Make a circuit as per above-given diagram to upload code to ESP8266. Make changes to SSID and Password in code and upload the code to ESP8266 using Arduino IDE. Open the Serial monitor IP in your browser after Serial monitor shows “Server listening” It will look like as blow given screenshot.

For information about uploading code to ESP8266 Click Here

How to Program ESP8266 with Arduino UNO
.

 #include 
 #include  

 ESP8266WebServer server(80);
 
 const char* ssid = "WiFi_SSID"; //Enter Wi-Fi SSIDconst 
 char* password =  "WiFi_Password"; //Enter Wi-Fi Passwordvoid 
 
 setup() 
{
    Serial.begin(115200); //Begin Serial at 115200 Baud 
    WiFi.begin(ssid, password);  //Connect to the WiFi network

    while (WiFi.status() != WL_CONNECTED) {  //Wait for connection
    delay(500); 
    Serial.println("Waiting to connect...");
    }
    
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());  //Print the local IP

    server.on("/", handle_index); //Handle Index page
    server.begin(); //Start the server
    Serial.println("Server listening");
}

 void loop()
 {
     server.handleClient(); //Handling of incoming client requests
 }void handle_index()
   {
      //Print Hello at opening homepage 
      server.send(200, "text/plain", "Hello! This is an index page.")
   }