Creating a Soft Access Point with ESP8266

An access point is a device that creates a wireless local area network (WLAN), usually in an office or large building. It connects to a wired router, switch, or hub via an Ethernet cable and projects a Wi-Fi signal to a designated area. While the ESP8266 Wi-Fi module can be configured as an access point, it lacks an Ethernet connection, making it suitable primarily for configuration purposes such as setting the SSID and password.


 NodeMCU as an Access Point


This guide demonstrates how to configure the ESP8266 to run in soft access point (soft-AP) mode. This allows Wi-Fi devices (stations) to connect to it. The established network can be identified with the SSID set during configuration and may be password-protected or open.


Wi-Fi Modes


Devices that connect to a Wi-Fi network are called stations (STA). An access point (AP) acts as a hub for these stations and is usually integrated with a router to provide internet access. Each AP is identified by an SSID, which is the network name you select when connecting a device.


The ESP8266 can operate in three modes:

- **Station mode (STA)**: Connects the ESP8266 to an existing Wi-Fi network.

- **Soft access point mode (AP)**: Creates its own Wi-Fi network.

- **Station and access point mode (AP_STA)**: Operates in both modes simultaneously, allowing the ESP8266 to connect to a network while creating its own.


Wi-Fi modes can be set using:

WiFi.mode(WIFI_AP); // Access Point Only

WiFi.mode(WIFI_STA); // Station Mode Only

WiFi.mode(WIFI_AP_STA); // Both Modes AP and STA



 Creating an Access Point


You can create a password-protected network or an open network:

- **Password Protected Network**:

  WiFi.softAP(ssid, password);


- **Open Network**:

  WiFi.softAP(ssid);


 Example: Creating a Soft Access Point


This example demonstrates how to configure the ESP8266 as a soft access point.


 Required Hardware

- NodeMCU (ESP8266 module)


 Code

#include <ESP8266WiFi.h>


// Enter SSID and Password for ESP8266

const char* ssid = "Your_SSID";

const char* password = "Your_Password";


void setup() {

  Serial.begin(115200);

  Serial.println();


  Serial.print("Setting up soft-AP ... ");

  WiFi.softAP(ssid, password);

  Serial.print("Access Point: ");

  Serial.print(ssid);

  Serial.println(" Started");

}


void loop() {

  int dev = WiFi.softAPgetStationNum();

  Serial.printf("Devices connected = %d\n", dev);

  delay(3000);

}


1. **Setup**: The setup function initializes the serial communication and configures the ESP8266 as a soft access point with the specified SSID and password.

2. **Loop**: The loop function periodically prints the number of devices connected to the access point.


Running the Example


1. Upload the sketch to the NodeMCU.

2. Open the serial monitor to view the output.

3. Use a mobile phone or PC to search for available Wi-Fi networks, find the SSID of the ESP8266, and connect to it.

4. The serial monitor will reflect the connection status, showing the number of connected devices.


Stations connected = 0

Stations connected = 1

Stations connected = 1



Connect additional devices to see the updated count:


Stations connected = 2



Conclusion


Setting up the ESP8266 as a soft access point is straightforward and provides a versatile way to create a Wi-Fi network for configuration or other purposes. The ability to operate in various modes makes the ESP8266 a powerful tool for wireless networking projects.


No comments

Theme images by Dizzo. Powered by Blogger.