Table of Contents

Dual Mode on the ESP32 refers to the ability to operate simultaneously in both Station (STA) mode and Access Point (AP) mode. The dual mode enables the ESP32 to communicate with both local devices (via AP mode) and joins in wireless network (via STA mode) simultaneously.

This is useful in scenarios where the ESP32 needs to communicate with both an existing Wi-Fi network and local devices at the same time. For example, you might use the ESP32 in an IoT project where it needs to access the internet (via STA mode) while also allowing users to configure or control it (via AP mode).

#include <WiFi.h>

// Replace with your network credentials
const char* ssid_sta = "your_SSID";  // SSID for STA Mode
const char* password_sta = "your_PASSWORD";  // Password for STA Mode

const char* ssid_ap = "LonelyBinaryESP32AP";  // SSID for AP Mode
const char* password_ap = "12345678";  // Password for AP Mode

void setup() {
  // Start serial communication
  Serial.begin(115200);

  // Start the ESP32 in Station Mode
  WiFi.begin(ssid_sta, password_sta);
  Serial.println("Connecting to Wi-Fi...");

  // Wait for the connection to establish
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting...");
  }

  // Once connected, print the IP address of the ESP32 in STA mode
  Serial.println("Connected to Wi-Fi!");
  Serial.print("STA IP Address: ");
  Serial.println(WiFi.localIP());

  // Start the ESP32 in Access Point Mode
  WiFi.softAP(ssid_ap, password_ap);

  // Print the IP address of the ESP32 in AP mode
  Serial.print("AP IP Address: ");
  Serial.println(WiFi.softAPIP());
}

void loop() {
  // Nothing to do here, the ESP32 is in dual mode (STA and AP)
}

All the codes are basically combined from the previous chatpers Station Mode and Access Point Mode.

Categorized in:

WiFi,

Tagged in: