Random Nerd Tutorials
Shares

How to Set an ESP32 Access Point (AP) for Web Server

Shares

The ESP32 can act as a Wi-Fi station, as an access point, or both. In this tutorial we’ll show you how to set the ESP32 as an access point using the Arduino IDE programming environment.

In most projects with the ESP32, we connect the ESP32 to a wireless router (see our ESP32 web server tutorial). This way we can access the ESP32 through the local network. In this situation the router acts as an access point and the ESP32 is set as a station. In this scenario, you need to be connected to your router (local network) to control the ESP32.

But if you set the ESP32 as an access point (hotspot), you can be connected to the ESP32 using any device with Wi-Fi capabilities without the need to connect to your router. In simple words, when you set the ESP32 as an access point you create its own Wi-Fi network and nearby Wi-Fi devices (stations) can connect to it (like your smartphone or your computer).

Here we’ll show you how to set the ESP32 as an access point in your web server projects. This way, you don’t need to be connected to a router to control your ESP32. Because the ESP32 doesn’t connect further to a wired network (like your router), it is called soft-AP (soft Access Point).

Installing the ESP32 board in Arduino IDE

There’s an add-on for the Arduino IDE that allows you to program the ESP32 using the Arduino IDE and its programming language. Follow one of the following tutorials to prepare your Arduino IDE:

ESP32 Access Point

In this example, we’ll modify an ESP32 Web Server from a previous tutorial to add access point capabilities. What we’ll show you here should work just fine with any ESP32 web server example.

Upload the sketch provided below to set the ESP32 as an access point.

Customize the SSID and Password

You need to define a SSID name and a password to access the ESP32. In this example we’re setting the ESP32 SSID name to “ESP32-Access-Point“, but you can modify the name to whatever you want. The password is 123456789, but you can also modify it.

// You can customize the SSID name and change the password
const char* ssid = "ESP32-Access-Point";
const char* password = "123456789";

Setting the ESP32 as an Access Point

There’s a section in the setup() to set the ESP32 as an access point using the softAP() method:

WiFi.softAP(ssid, password);

There are also other optional parameters you can pass to the softAP() method. Here’s all the parameters:

.softAP(const char* ssid, const char* password, int channel, int ssid_hidden, int max_connection)
  • SSID (defined earlier): maximum of 63 characters;
  • password (defined earlier): minimum of 8 characters; set to NULL if you want the access point to be open
  • channel: Wi-Fi channel number (1-13)
  • ssid_hidden: (0 = broadcast SSID, 1 = hide SSID)
  • max_connection: maximum simultaneous connected clients (1-4)
cloud-download

Next, we need to print the access point IP address using the softAPIP() method and print it in the Serial Monitor.

IPAddress IP = WiFi.softAPIP(); 
Serial.print("AP IP address: "); 
Serial.println(IP);

These are the snippets of code you need to include in your web server sketches to set the ESP32 as an access point. To learn how the rest of the code works, take a look at the ESP32 Web Server tutorial.

Parts Required

For this tutorial you’ll need the following parts:

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Schematic

Start by building the circuit. Connect two LEDs to the ESP32 as shown in the following schematic diagram – one LED connected to GPIO 26, and the other to GPIO 27.

Note: We’re using the ESP32 DEVKIT DOIT board with 36 pins. Before assembling the circuit, make sure you check the pinout for the board you’re using.

ESP32 IP Address

Upload the code to your ESP32 (make sure you have the right board and COM port selected). Open the Serial Monitor at a baud rate of 115200. Press the ESP32 “Enable” button.

The IP address you need to access the ESP32 point will be printed. In this case, it is 192.168.4.1.

Connecting to the ESP32 Access Point

Having the ESP32 running the new sketch, in your smartphone open your Wi-Fi settings and tap the ESP32-Access-Point network:

Enter the password you’ve defined earlier in the code.

Open your web browser and type the IP address 192.168.4.1. The web server page should load:

To connect to the access point on your computer, go to the Network and Internet Settings and select the “ESP32-Access-Point“.

Insert the password you’ve defined earlier.

And it’s done! Now, to access the ESP32 web server page, you just need to type the ESP32 IP address on your browser.

Wrapping Up

This is just a simple tutorial that shows how to set the ESP32 as an access point on your web server sketches. When the ESP32 is set as an access point, devices with Wi-Fi capabilities can connect directly to the ESP32.

You may also like reading:

We hope you’ve found this tutorial useful. If you like ESP32 and you want to learn more, we recommend enrolling in Learn ESP32 with Arduino IDE course.

Thanks for reading.


Learn ESP32 with Arduino IDE

This our complete guide to program the ESP32 with Arduino IDE, including projects, tips, and tricks! The registrations are open, so SIGN UP NOW »

Leave a Comment:

Add Your Reply

⏰ Registrations are open ⏰
Sign up for "Learn ESP32 with Arduino IDE" Course