ESP as a WiFi access point: creating a DIY network

Turning an ESP8266 or ESP32 microcontroller into a fully-fledged access point opens up enormous possibilities for IoT developers. Instead of relying on external infrastructure, you create a standalone network that the device manages itself. This is an ideal solution for smart homes, portable gadgets, and systems where a router may be unavailable.

SoftAP (Software Access Point) Allows the chip to operate as a server, distributing IP addresses to connected clients. This architecture is often used for initial device setup when data needs to be transmitted from the main home network. This gives you complete control over communication processes without intermediaries.

In this article, we'll explore the technical nuances of implementing access point mode. You'll learn how to set up a web interface for management, what hardware limitations apply, and how to ensure a stable connection. fundamental knowledge for any engineer working with wireless technologies.

How ESP works in SoftAP mode

When the microcontroller switches to access point mode, it assumes the functions of a router. The device begins broadcasting the SSID (network name) and waits for connections from clients such as smartphones or laptops. At this point, ESP8266 or ESP32 creates a local subnet with its own gateway.

It's important to understand the difference between Station and AP modes. In Station mode, the device connects to an existing router, receiving internet from it. In Access Point mode, the device itself becomes the center of the network. These modes are often combined: first, the device distributes the network for configuration, and then switches to client mode to work with the cloud.

⚠️ Attention: When operating in access point mode, the chip's power consumption increases significantly. The radio module operates continuously, emitting a signal, which can quickly drain the battery when powered by battery power.

The default network configuration typically uses addresses in the 192.168.4.x range. Once connected to the network, the client receives an IP address via the built-in DHCP server. This allows for instant access to web management pages by simply entering the gateway address in the browser. Flexibility of customization Allows you to change address ranges and subnet masks to suit your needs.

Necessary equipment and environment preparation

To implement the project you will need a development board based on ESP8266 (eg NodeMCU or Wemos D1 Mini) or more powerful ESP32These boards feature a built-in Wi-Fi module and a USB port for programming. You'll also need a computer with the Arduino IDE or PlatformIO development environment installed.

Don't forget to install the required libraries in the board manager. For the ESP8266, this is the package from esp8266com, and for ESP32 - the official package from espressifWithout these additions, the compiler will not be able to correctly handle specific Wi-Fi kernel functions. Ensure that the USB converter drivers (CH340 or CP2102) are installed in the system.

The choice between the two popular chip families depends on the application. The ESP32 has two cores and supports Bluetooth, which provides an advantage in multitasking. However, for simple access point tasks, the classic ESP8266 is sufficient, being cheaper and easier to learn.

  • 📟 ESP8266 or ESP32 board (NodeMCU, Wemos, TTGO)
  • 🔌 Micro-USB or Type-C data cable
  • 💻 A PC with the Arduino IDE or VS Code installed
  • 📡 A smartphone for testing the connection to the created network
📊 What board are you planning to use?
ESP8266 (NodeMCU)
ESP32 DevKit
ESP32-C3
Another board

Basic Access Point Setup in the Arduino IDE

The programming process begins with connecting the library ESP8266WiFi.h or WiFi.h for ESP32. These header files contain all the necessary classes for managing the wireless interface. In the function setup We initialize the operating mode and set the network parameters.

The code should be concise and clear. We declare the SSID and password, and then call the method WiFi.softAPThis method starts the access point with the specified parameters. After successful startup, it's useful to output the gateway's IP address to the serial port for debugging.

#include<WiFi.h> // For ESP32, for ESP8266 use ESP8266WiFi.h

const char* ssid ="MyESP_Hotspot";

const char* password ="12345678";

void setup {

Serial.begin(115200);

WiFi.softAP(ssid, password);

IPAddress IP = WiFi.softAPIP;

Serial.print("AP IP address:");

Serial.println(IP);

}

Please pay attention to the password length. For WPA2 encryption, which is the default, the password must be at least 8 characters long. If you specify a shorter string, the access point may start in open mode or return a compilation error, depending on the kernel version. Security The connection starts with the correct password.

☑️ Pre-launch check

Completed: 0 / 4

Organizing a web interface for management

The access point itself is only useful as a transport. To interact with the device, an interface is needed. The simplest way is a built-in web server. Library ESP8266WebServer.h (or equivalent for ESP32) allows you to process HTTP requests and return HTML pages directly from the microcontroller's memory.

You can create an HTML string variable containing the page markup with buttons and input fields. When the client accesses the root path / The server will return this HTML code. This allows you to create beautiful control panels with graphs and switches without using external hosting.

⚠️ Attention: Microcontroller memory is limited. Storing large HTML pages, CSS, and JS scripts in code (in strings) quickly exhausts the available RAM. For complex interfaces, use the SPIFFS or LittleFS file system.

To handle user actions, such as turning on an LED, separate path handlers are created. For example, a request /ledon will execute the command digitalWrite(LED_BUILTIN, HIGH) and return the "OK" status. This approach makes device management intuitive via a browser.

Example HTML code for embedding

Instead of complex libraries, you can use a simple string: String html ="<html><body><h1> Control</h1> <a href='/ledon'>ON</a></body></html> "; This will take up minimal memory, but will allow you to control the device.

Comparison of ESP8266 and ESP32 performance in AP mode

When choosing a platform, it's important to consider technical limitations. Although both chips support access point mode, their performance and capabilities differ. The ESP32 supports the 802.11 b/g/n standard, while the ESP8266 is limited to b/g/n with a lower modulation rate.

The number of simultaneous connections is a critical parameter. The standard firmware allows for multiple clients, but overloading the TCP/IP stack can lead to a reboot. The ESP32 handles a higher number of connections thanks to its dual-core processor and larger RAM.

Characteristic ESP8266 ESP32
Max clients (SoftAP) ~4-5 stable ~10 or more
IPv6 support Limited Full
Wi-Fi speed up to 72.2 Mbps up to 150 Mbps
Consumption (TX) ~200 mA ~260 mA

The choice between them depends on your budget and project requirements. For a simple light switch that needs to be configured once a year, the ESP8266 is suitable. If you're building a smart home gateway with a permanent interface, ESP32 will be a more reliable choice.

Connection compatibility and stability issues

Not all client devices readily connect to homemade access points. Modern smartphones may mark the network as "Connected, no internet access" and automatically switch to mobile data. This can interrupt the setup session.

To solve this problem, a Captive Portal mechanism is used. The device redirects any DNS request to its IP address, opening an authorization or configuration page. This is standard for public Wi-Fi networks in hotels and cafes, and is successfully emulated by ESPs.

Broadcast channels are also worth considering. By default, the ESP selects a specific channel, but in noisy environments (such as with many neighboring routers), the connection may be unstable. Forced channel selection (for example, 1, 6, or 11) can sometimes help improve signal quality.

  • 📶 Problem: My phone won't open the settings page. Solution: Turn on mobile data and try again.
  • 🔒 Problem: Authentication error. Solution: Check the password length and encryption type (WPA2).
  • 🔋 Problem: The device reboots when connected. Solution: Insufficient power; a high-quality USB cable is needed.

Frequently Asked Questions (FAQ)

Can ESP work as an access point and a client at the same time?

Yes, this is AP+Station mode. However, in access point mode, throughput drops because the radio module splits its time between listening to clients and connecting to the external router. This can cause delays in data transfer.

What is the maximum range of an ESP access point?

The range depends on the antenna. With the built-in PCB antenna, the range is 10-20 meters indoors. With an external antenna (via an IPEX connector), the range can be increased to 50-100 meters with a direct line of sight.

Is internet required for ESP to operate in AP mode?

No, internet access is not required. The access point creates a local network. You can control the device, transfer files, or read sensor data while within Wi-Fi range, even without a global network connection.

Is it safe to leave the ESP access point open?

This is strongly discouraged. Anyone within range will be able to connect to your network and access your device. Always use a password and, if possible, change it after initial setup.