'' !! What is SoftAP? The Secret Behind Offline ESP32 Projects !!''

 

 

'' What is SoftAP Mode ? ''


SoftAP stands for Software-enabled Access Point.

When an ESP32 runs in SoftAP mode, it creates its own Wi-Fi network — just like a Wi-Fi router. Devices like phones or laptops can connect directly to the ESP32, without needing a separate router or internet.


ESP32 Operating Modes

Mode

Description

STA

Station mode (ESP32 connects to existing Wi-Fi)

AP (SoftAP)

Access Point mode (ESP32 creates a Wi-Fi network)

STA + AP

Dual mode (ESP connects to Wi-Fi and acts as hotspot)



                                                            
                                                                     



  
 
                   

 ESP32 in SoftAP Mode: Full Process Breakdown


Initialization

You begin by setting ESP32 into AP mode using this function:

WiFi.mode(WIFI_AP);

WiFi.softAP("ESP_Hotspot", "12345678");

  • This tells the ESP32 to enable its internal Wi-Fi transceiver and behave like a Wi-Fi router.
  • "ESP_Hotspot" is the Wi-Fi network name (SSID).
  • "12345678" is the WPA2 password (minimum 8 characters).

Beacon Frame Broadcasting

  • After enabling SoftAP, the ESP32 starts broadcasting "beacon frames" every ~100 milliseconds.
  • These are special packets sent at Layer 2 (Data Link Layer) over 2.4 GHz frequency.
  • beacon frames is a signal packet generate by esp32

Nearby devices (phones/laptops) detect this broadcast when they scan for networks.


 DHCP and IP Assignment

Once a device connects to the ESP32 network:

  • ESP32 runs a DHCP server.
  • It assigns a local IP to the device (e.g., 192.168.4.2).
  • ESP32 itself keeps 192.168.4.1.by default.

 DHCP Range (default for ESP):

  • Subnet: 192.168.4.0/24
  • ESP IP: 192.168.4.1
  • Clients: 192.168.4.2, .3, .4, up to ~4 clients by default

Communication

Once connected, devices can communicate with the ESP32 using:

  • HTTP Web Server: ESP32 serves web pages at 192.168.4.

I current used only this method but other are also different way ,


No Internet Required

  • SoftAP mode works completely offline.
  • ESP32 doesn’t connect to the internet.
  • Useful for:
    • Local control of devices
    • Configuration setup (e.g., Wi-Fi credentials)
    • Mobile apps that connect directly to ESP

 Real-World Use Cases

 Mobile-based LED control

    • Phone connects to ESP's Wi-Fi
    • ESP-based sensors in remote areas
    • Local access using phone or tablet
    • ESP hosts a web page with ON/OFF buttons

Technical Details

Feature

Value

Frequency

2.4 GHz only

Max clients

Default is 4, max ~8

IP address (default)

192.168.4.1

Encryption

WPA2-PSK

SSID broadcast

Through beacon frames

DHCP server

Built-in (assigns IP to clients)


 Sample Code: ESP32 as SoftAP

#include<WiFi.h>

void setup()

{

  Serial.begin(115200);

  WiFi.softAP("kailash WiFi","electrokailash");// WiFi name and password(atleast 8 character)

  Serial.println("Access Point started");

  Serial.println("AP IP address is");

  Serial.println(WiFi.softAPIP());

}

void loop()

{

  //

}

 

                                                 video link:


 

Line-by-Line Explanation

#include <WiFi.h>

  • Includes the WiFi library needed for Wi-Fi functionality on ESP32.
  • This library provides functions like softAP(), begin(), and softAPIP().

WiFi.softAP("kailash WiFi", "electrokailash");

  • This puts the ESP32 in SoftAP (Access Point) mode.
  • It starts broadcasting a Wi-Fi network:
    • SSID (Wi-Fi name): "kailash WiFi"
    • Password: "electrokailash" (must be at least 8 characters for WPA2 security)

 This creates a secure WPA2-PSK Wi-Fi hotspot that nearby devices can connect to.


 Serial.println(WiFi.softAPIP());

  • Retrieves and prints the IP address of the ESP32 Access Point.
  • Default IP is usually 192.168.4.1.

 void loop()

  • The loop() is currently empty, meaning no code runs
  • You can add server logic here (e.g., a web server to serve HTML, or handle client requests).

 


WEBServer code:

 

#include <WiFi.h>  // note this is for esp32


WiFiServer server(80);

WiFiClient client;

 

#define LED_PIN 2  // GPIO2 (built-in LED)

 

void setup() {

  Serial.begin(9600);

 

  // Start Access Point

  WiFi.softAP("make your wifi name", "make 8 digit password ");

  Serial.println("AP IP: " + WiFi.softAPIP().toString());

 

  server.begin();

 

  pinMode(LED_PIN, OUTPUT);

  digitalWrite(LED_PIN, LOW);

}

 

void loop() {

  client = server.available();  // Wait for client

 

  if (client) {

    String request = client.readStringUntil('\r');

    Serial.println("Request: " + request);

    client.flush();

 

    if (request.indexOf("GET /ledon") != -1) {

      digitalWrite(LED_PIN, HIGH);

    }

    else if (request.indexOf("GET /ledoff") != -1) {

      digitalWrite(LED_PIN, LOW);

    }

 

    // Simple centered HTML switch UI

    client.println("HTTP/1.1 200 OK");

    client.println("Content-Type: text/html");

    client.println("Connection: close");

    client.println();

    client.println("<!DOCTYPE html><html><head><title>LED Control</title>");

    client.println("<style>body{display:flex;justify-content:center;align-items:center;height:100vh;font-family:sans-serif;} a{padding:15px 25px;margin:10px;text-decoration:none;background:#007BFF;color:white;border-radius:8px;}</style>");

    client.println("</head><body>");

    client.println("<a href=\"/ledon\">LED ON</a>");

    client.println("<a href=\"/ledoff\">LED OFF</a>");

    client.println("</body></html>");

 

    client.stop();

    Serial.println("Client disconnected");

  }

}

 

 

 

 





Comments

Popular posts from this blog

Astable circuit using 555 timer ic

LDR base solar light tracking system using Transistor DIY project

Monostable circuit using 555 timer ic