ESP32 Access point (AP) and Station web server with HTML using Arduino IDE

In this tutorial we are making ESP32 as both Station and Access point and web server. We have seen how to connect to WiFi Router and make web server in previous post.

What you will Learn?

  1. Making ESP32 as Access Point
  2. ESP32 as Station
  3. ESP32 as both Station and Access Point at the same time
  4. ESP32 as web server with HTML web page
  5. Using Java Scripts in ESP32
  6. Using CSS in ESP32

A Web server is a program that uses HTTP (Hypertext Transfer Protocol) to serve the files that form Web pages to users, in response to their requests, which are forwarded by their computers’ HTTP clients.

ESP32 Access point web server

To implement web server on ESP32, there are two ways to make your first web server first connect to your WiFi router or make ESP32 as access point.

Web Server Step by Step

As we know that all web servers have a HTML web page to be served.

Step 1: Creating web server on ESP32

ESP can acts as access point and it can connect to access point or both.

First we make program to connect to WiFi hot spot (Access Point)

Program to connect to Access point and Make web server

We need these libraries to make web server.

WiFi.h is required for doing all WiFi related functionalities such as connection, AP, etc.

WiFiClient.h this file is required to send request to web browser

WebServer.h it handles all HTTP protocols

Define your SSID and Password of your WiFi router, where the ESP32 connects

Web server is on port 80, you can use other ports also, default HTTP port is 80, to open web page with different port number you have to enter port number after IP address. Ex. For port number 81 you have to type in browser.

There are two ways to make web server one is to connect to WiFi hot spot or make ESP as hot spot (Access Point). In this tutorial we are making ESP as AP.

ESP as Access Point

You may find that ESP is also visible as hot spot in previous example; you can hide its AP (Access point) using this command at the beginning of setup.

In some application you may find that both AP and connection to WiFi router are useful for making configuration you use ESP8266 AP and for data sending to cloud use WiFi connectivity in that case use this command and both connections. This way you can access ESP web page with two different IP address.

Third way is only access point, default is all AP and STA are enabled, to get only AP use this command.

To start ESP as Access point you have to use this simple command

To get IP address i.e. assigned to ESP32 by your WiFi router use this command

Web Server Handling

When client request a web page by entering ESP32 IP address which data to be sent is handled by subroutine and that subroutine name is defined in server.on(path,subroutine_name).

Example: If you have two pages you can define like this

Server.on(“/”,root); // (IP of ESP) this is root location

Server.on(“/page1”,First_page); //”” this is first page location

Server.on(“/page2”,Second_page); //”” this is second page location

You have three subroutines that handle client requests.

To start the server use this command

In main loop we handle client request

This subroutine is called when you enter IP address in web browser and hit enter. This routine sends the test “hello from esp32” to web browser.

Complete Program for HTML web Server from esp32 as Access Point


Make separate header file for storing HTML code. keep this index.h file near to ino file

WebServer.ino code


After uploading program take your mobile turn on WiFi and in WiFi setting Scan for hot spot you will find “ESPWebServer” hot spot connect to it with password “12345678” as we have given in program. After connecting to ESP hot spot, Open web browser in mobile phone and enter IP you will see “HTML snake game”. IP address can be found in serial monitor.

Open web browser and enter the IP

Web Server results In next post we will see how to make ESP8266 Web Server and Load HTML Web Page.

2 thoughts on “ESP32 Access point (AP) and Station web server with HTML using Arduino IDE

  1. The article was very informative and helpful.
    But I do have a point of confusion.

    in the index.h file you have this construct–

    const char MAIN_page[] PROGMEM = R”=====(


    I understand that PROGMEM forces it to program memory,

    but the R”=====( … )=====” is something I’ve not seen before.
    It appears to allow you to spread the string definition over several lines in the file, but how does it work?
    Where is it defined?
    Is it part of C++ or an Arduino SDK macro?
    Thanks for the help


Leave a Reply