ESP32 WiFi Library – WiFi.softAP

Home / References / ESP32 Library / WiFi API / AP

Description

The softAP method in the ESP32 WiFi library is used to set up the device as an Access Point (AP), allowing it to broadcast its own WiFi network. This method enables the ESP32 to function as a WiFi hotspot, allowing other devices to connect to it.


Syntax and Usage

The softAP method can be used in different ways:

With SSID Argument:

WiFi.softAP(ssid);

This usage sets the SSID of the Access Point. No password is set by default.

With SSID and Password Arguments:

WiFi.softAP(ssid, password);

This usage sets both the SSID and password for the Access Point. This is a more secure option as it requires a password for devices to connect to the network.

With SSID, Password, Channel, Hidden, and Maximum Connections Arguments:

WiFi.softAP(ssid, password, channel, hidden, max_connection);

This usage allows you to set the SSID, password, WiFi channel, hidden SSID, and the maximum number of simultaneous connections allowed to the Access Point. The maximum number of connections can range from 1 to 4.

For practical applications and examples of this method, please consult the “Example Code” section on this page. This section provides comprehensive guidance to help you better understand and apply the method effectively.


Argument(s)

  • ssid:The Service Set Identifier (SSID) for the Access Point. It represents the name of the WiFi network that will be broadcasted by the ESP32.
  • password (optional):The password required to connect to the Access Point. If no password is provided, the network will be open (no security).
  • channel (optional):The WiFi channel for the Access Point. Valid values are between 1 and 13. If not provided, the default channel is used.
  • hidden (optional):Whether to hide the SSID (boolean). true hides the SSID, false makes it visible.
  • maxConnections (optional):The maximum number of clients that can connect to the Access Point. Valid values range from 1 to 4. The default is 4.
    NOTE: Despite this limitation in the function parameter, the ESP32 can actually support up to 10 connections in AP mode. It’s important to note that while the theoretical maximum is 10 devices, connecting too many devices may affect the performance and stability of the Wi-Fi module. Therefore, it’s generally recommended to limit the number of connections to ensure optimal performance.

Return Value

The softAP method returns a boolean value:

  • true: The Access Point was successfully created.
  • false: There was an error in creating the Access Point.

Example Codes

Below are three example codes demonstrating the usage and syntax of the softAP method from the ESP32 WiFi Library. Each example demonstrates different configurations for setting up the ESP32 as an Access Point.

Example 1: Using softAP to create an open WiFi Access Point

This code demonstrates how to use the ESP32 AP (Access Point) class’s softAP() method to create a custom WiFi network. The ESP32 acts as an Access Point, allowing other devices to connect directly to it. In this example, the code creates an open WiFi Access Point, meaning other devices can connect to it without requiring a password. If you need to create a password-protected WiFi Access Point, refer to the example code 2 below. Once the Access Point is successfully created, the code retrieves and prints the IP address assigned to the ESP32 using the softAPIP() method, which is useful for local communication or configuration in IoT projects.

To use this code, upload it to your ESP32 and open the Serial Monitor at 115200 baud. Replace “AvantMaker-ESP32-AP” with your desired network name (SSID). After the ESP32 starts the Access Point, connect to it from another device using the same SSID. The Serial Monitor will display the IP address of the ESP32, which can be used for further communication or configuration. Ensure no other conflicting networks are present to avoid connection issues.

/*
 * Author: Avant Maker
 * Date: February 7, 2025
 * Version: 1.0
 * Description: This example shows how to use ESP32 WiFi Library's
 * softAP method to create an Access Point. The created network's
 * SSID is AvantMaker-ESP32-AP. The network is open and user can connect this
 * network without password.
 *
 * License: MIT 
 * 
 * Code Source: This example code is sourced from the Comprehensive Guide
 * to the ESP32 Arduino Core Library, accessible on AvantMaker.com. 
 * For additional code examples and in-depth documentation related to 
 * the ESP32 Arduino Core Library, please visit:
 *
 * https://avantmaker.com/references/esp32-arduino-core-index/
 *
 * AvantMaker.com, your premier destination for all things DIY, AI, IoT, 
 * Smart Home, and STEM projects. We are dedicated to empowering makers,
 * learners, and enthusiasts with the resources they need to bring their 
 * innovative ideas to life.
 */

#include <WiFi.h>  // Include the ESP32 WiFi library

const char* ssid = "AvantMaker-ESP32-AP";  // Custom SSID for the Access Point

void setup() {
  // Start Serial communication for debugging
  Serial.begin(115200);
  
  // Set up the ESP32 as an Access Point with the custom SSID
  Serial.println("Setting up Access Point...");
  if (WiFi.softAP(ssid)) {
    // If the Access Point is created successfully
    Serial.println("Access Point started successfully!");
    Serial.print("IP Address: ");
    Serial.println(WiFi.softAPIP());  // Print the IP address of the AP
  } else {
    // If there was an error creating the Access Point
    Serial.println("Failed to start Access Point.");
  }
}

void loop() {
  // Nothing to do in the loop for this example
}

Example 2: Using softAP With SSID and Password Arguments

This code demonstrates how to use the ESP32 AP (Access Point) class’s softAP() method to create a secure, password-protected WiFi network. The ESP32 acts as an Access Point, allowing other devices to connect using the specified SSID and password.

To use this code, upload it to your ESP32 and open the Serial Monitor at 115200 baud. Replace “AvantMaker-SecureESP32-AP” and “12345678” with your desired SSID and password. Once the Access Point is started, connect to it from another device using the specified credentials. The Serial Monitor will display the IP address of the ESP32, which can be used for further communication. Ensure the password is strong enough to meet security requirements and avoid conflicts with other nearby networks.

/*
 * Author: Avant Maker
 * Date: February 7, 2025
 * Version: 1.0
 * Description: This example shows how to use ESP32 WiFi Library's
 * softAP method to create a secure Access Point with both an SSID
 * and a password. The created network's SSID is AvantMaker-SecureESP32-AP.
 * The network is protected with a password.
 *
 * License: MIT 
 * 
 * Code Source: This example code is sourced from the Comprehensive Guide
 * to the ESP32 Arduino Core Library, accessible on AvantMaker.com. 
 * For additional code examples and in-depth documentation related to 
 * the ESP32 Arduino Core Library, please visit:
 *
 * https://avantmaker.com/references/esp32-arduino-core-index/
 *
 * AvantMaker.com, your premier destination for all things DIY, AI, IoT, 
 * Smart Home, and STEM projects. We are dedicated to empowering makers,
 * learners, and enthusiasts with the resources they need to bring their 
 * innovative ideas to life.
 */

#include <WiFi.h>  // Include the ESP32 WiFi library

const char* ssid = "AvantMaker-SecureESP32-AP";  // Custom SSID for the Access Point
const char* password = "12345678";  // Password for the Access Point

void setup() {
  // Start Serial communication for debugging
  Serial.begin(115200);
  
  // Set up the ESP32 as an Access Point with SSID and password
  Serial.println("Setting up Access Point with password...");
  if (WiFi.softAP(ssid, password)) {
    // If the Access Point is created successfully
    Serial.println("Access Point started successfully with password!");
    Serial.print("IP Address: ");
    Serial.println(WiFi.softAPIP());  // Print the IP address of the AP
  } else {
    // If there was an error creating the Access Point
    Serial.println("Failed to start Access Point.");
  }
}

void loop() {
  // Nothing to do in the loop for this example
}

Example 3: Using softAP With SSID, Password, Channel, Hidden, and Maximum Connections Arguments

This code demonstrates how to use the ESP32 AP (Access Point) class’s softAP() method to create a fully customized WiFi network. It allows you to configure various parameters, including the SSID, password, WiFi channel, hidden network setting, and the maximum number of allowed connections. This example highlights the flexibility of the ESP32 in creating tailored Access Points for specific project requirements, such as secure local communication or IoT device management.

To use this code, upload it to your ESP32 and open the Serial Monitor at 115200 baud. Customize the SSID, password, WiFi channel, hidden setting, and maximum connections by modifying the respective variables. After the Access Point starts, connect to it using the specified credentials. The Serial Monitor will display the IP address of the ESP32, which can be used for further interaction. Ensure the settings align with your project needs and avoid conflicts with nearby networks for optimal performance.

/*
 * Author: Avant Maker
 * Date: February 7, 2025
 * Version: 1.0
 * Description: This example shows how to use ESP32 WiFi Library's 
 * softAP method to create a fully customized Access Point with an 
 * SSID, password, WiFi channel, hidden network setting, and maximum
 * number of allowed connections. 
 *
 * License: MIT 
 * 
 * Code Source: This example code is sourced from the Comprehensive Guide
 * to the ESP32 Arduino Core Library, accessible on AvantMaker.com. 
 * For additional code examples and in-depth documentation related to 
 * the ESP32 Arduino Core Library, please visit:
 *
 * https://avantmaker.com/references/esp32-arduino-core-index/
 *
 * AvantMaker.com, your premier destination for all things DIY, AI, IoT, 
 * Smart Home, and STEM projects. We are dedicated to empowering makers,
 * learners, and enthusiasts with the resources they need to bring their 
 * innovative ideas to life.
 */

#include <WiFi.h>  // Include the ESP32 WiFi library

const char* ssid = "CustomESP32-AP";  // Custom SSID for the Access Point
const char* password = "CustomPass123";  // Password for the Access Point
int channel = 6;  // WiFi channel (1-13)
bool hidden = false;  // Whether the network is hidden (true = hidden, false = visible)
int maxConnections = 3;  // Maximum number of devices that can connect to the AP (1 to 4)

void setup() {
  // Start Serial communication for debugging
  Serial.begin(115200);
  
  // Set up the ESP32 as an Access Point with SSID, password, channel, hidden setting, and max connections
  Serial.println("Setting up customized Access Point...");
  if (WiFi.softAP(ssid, password, channel, hidden, maxConnections)) {
    // If the Access Point is created successfully
    Serial.println("Access Point started successfully with custom settings!");
    Serial.print("IP Address: ");
    Serial.println(WiFi.softAPIP());  // Print the IP address of the AP
  } else {
    // If there was an error creating the Access Point
    Serial.println("Failed to start Access Point.");
  }
}

void loop() {
  // Nothing to do in the loop for this example
}

AvantMaker Tutorial Suggestion

If you want to learn more about the ESP32’s WiFi capabilities, we’ve created a beginner-friendly guide that explains them in detail. Just click the link below, and you’ll be teleported to that page. It will clear up any confusion you may have while connecting your ESP32 to WiFi or setting it up as a WiFi access point (AP).

ESP32 Essential Guide – Network Section – WiFi Chapter

ESP32 Library Index

ESP32 Arduino Core Library


FAQ

Ready to experiment and explore more about ESP32? Visit our website’s All About ESP32 Resources Hub, packed with tutorials, guides, and tools to inspire your maker journey. Experiment, explore, and elevate your skills with everything you need to master this powerful microcontroller platform!

error: Content is protected !!