ESP32 as Wireless Access Point
#include <>

Configuring an ESP32 as a Wi-Fi Access Point

by Xukyo | 21 Oct 2021 | Tutorials | 4 comments
Tags: ESP32, Wireless communication

Facebook
Twitter
Pinterest
Share
5
(7)

The ESP32 microcontroller from Espressif is able to be configured as an access 
point (AP) and generate its own wifi network with ssid and password. This method
is useful when you do not have access to a wifi network or if you want to work 
on a network specific to the microcontroller.

Material
    Computer
    NodeMCU ESP32
    USB A Male/Micro B Male Cable

Principle
The ESP32 NodeMCU has, among other things, a Wi-Fi chip that can generate its 
own network in the event that a Wi-Fi network is not available. This configuration
 is called AP (Access Point) mode.

Code
To configure the ESP32 NodeMCU as an access point, we will use the SoftAp class
included in the WiFi.h library. To configure a WiFi access point, you just have
to give it a name

WiFi.softAP(ssid)

Other parameters, such as the password or the connection limit can be set.

    ssid network ID (max. 31 characters)
    passphrase network password (min. 8, max. 63 characters) (Optional).
    network channel between 1 and 13. Default value 1 (Optional).
    ssid_hidden hides SSID if true (Optional).
    max_connection number of simultaneous connections allowed from 0 to 8. 
	Default value 4. (Optional).

/*F********************************************************************
*
**********************************************************************/
#include 

//************************* DEFINES ************************************
#define  BAUD  9600
const char *ssid = "AC-ESP32";
const char *passphrase = "987654321";

//************************* PROTOTYPES ************************************

//************************* VARIABLES ************************************
IPAddress local_IP( 192,168,4,22 );
IPAddress gateway( 192,168,4,9 );
IPAddress subnet( 255,255,255,0 );

/*F********************************************************************
*
**********************************************************************/
void 
setup()
{
	Serial.begin( BAUD );
	Serial.println();
	Serial.print( "Setting soft-AP configuration ... ");
	Serial.println( WiFi.softAPConfig( local_IP, gateway, subnet) 
		? "Ready" : "Failed!" );
	Serial.print( "Setting soft-AP ... " );
	Serial.println( WiFi.softAP( ssid, passphrase ) ? "Ready" : "Failed!");
	//WiFi.softAP( ssid );
	//WiFi.softAP( ssid, passphrase, channel, ssdi_hidden, max_connection )
	Serial.print( "Soft-AP IP address = " );
	Serial.println( WiFi.softAPIP() );
}
/*F********************************************************************
*
**********************************************************************/
void 
loop() 
{
	Serial.print( "[Server Connected] " );
	Serial.println( WiFi.softAPIP() );
	delay( 500 );
}

Note: If the assigned password is shorter than 8 characters, the SSID will be 
ignored. If you want to change the SSID, make sure the password is longer than 
8 characters or that there is no password.

If you do not call the softApConfig function to set the IP addresses, the network
 will use default addresses.

Results

Once the access point has been configured and the code uploaded to the card, a 
new network appears in the available networks. We check that it has the SSID 
defined in the code.

Once the ESP32 NodeMCU is configured as an access point, the resulting network 
can be used like any other Wi-Fi network. Other devices can connect and 
communicate via this network, such as other ESP32s or ESP8266s.

Applications
    Create a network of microcontrollers that communicate over a private network

Sources

    ESP32 SoftAP documentation
    Program an ESP32 with Arduino IDE