fbpixel
Tags: ,

The esp32 microcontroller from Espressif is able to be configured as an WiFi 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).
#include <WiFi.h>

const char *ssid = "AC-ESP32";
const char *passphrase = "987654321";

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

void setup()
{
  Serial.begin(115200);
  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());
}

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.

esp32-apmode-result Configuring an ESP32 as a Wi-Fi Access Point
esp32-apmode-monitor-result Configuring an ESP32 as a Wi-Fi Access Point

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