Site icon AranaCorp

Configuring an ESP32 as a Wi-Fi Access Point

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

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.

#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.

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

Sources

Exit mobile version