Access Point & Wi-Fi Station Mode with ESP8266

In This Tutorial, I will show you  Access Point & Wi-Fi Station Mode with ESP8266 step by step complete process. first I show you the assess point then Wi-Fi Station Mode.


≡ Required Component :


Here is a list of the hardware we suggest to Access Point & Wi-Fi Station Mode with ESP8266.

  1. NodeMcu8266
  2. Breadboard
  3. Connecting wire
  4. Breadboard Power Supply Module

≡ What is Access Point :


An access point is a device that generates a wireless local area network, or WLAN, normally in your sounding. An access point connects to a wired router, switch, or hub via an Ethernet cable, and projects a Wi-Fi signal to a selected area. ESP8266 Wi-Fi Access point is essentially used for configuration designs such as SSID and Password. It does not have an Ethernet connection so we cannot use it for internet access.


≡ NodeMCU as Access Point


Now we see how to configure ESP8266 to run in soft access point mode so Wi-Fi stations can connect with it. The Wi-Fi network installed by the soft-AP will be recognized with the SSID set during shape. The network protected by a password. The network may be too open if no password is set as a configuration.

Devices that join to Wi-Fi network named stations. Joint to Wi-Fi given by an access point, which acts as a center for one or more stations. The access point on the other end attached to a wired network. An access point is normally combined with a router to give access from the Wi-Fi network to the internet. Each access point accepted by an SSID, which actually is the name of the network you select when joining a device to the Wi-Fi.

ESP8266 module can work as a station, so we can attach it to the Wi-Fi network. It can also work as a soft access point, to set its own Wi-Fi network. For we can join other stations to such an ESP module. ESP8266 is also able to work both in station and soft access point mode. 

Wi-Fi Mode can be set in the access point, station, or both modes.

WiFi.mode(WIFI_AP); //Access Point Only
WiFi.mode(WIFI_STA); //Station Mode Only
WiFi.mode(WIFI_AP_STA); //Both Modes AP and STA

Password Protected Network

WiFi.softAP(ssid, password); //With Password

Open Network

WiFi.softAP(ssid);  //No password

≡ Creating Access Point using NodeMCU


#include <ESP8266WiFi.h>
//Enter SSID and Password for ESP8266
const char* ssid = "ssid_for_AP";
const char* password = "password_for_AP";
void setup()
{
  Serial.begin(115200);
  Serial.println();
  Serial.print("Setting 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);
}

After uploading the sketch, the open serial monitor

Wi-Fi Access Point ESP8266


≡ Connecting NodeMCU to Access Point


Now you can show how to configure ESP8266 to connect with the Wi-Fi access point. The Wi-Fi network recognized with the SSID and Password. The network protected with a password. NodeMCU can connect to a hidden network also.

#include <ESP8266WiFi.h>
//Enter SSID and Password of your Wi-Fi Router
const char* ssid = "Mechatronics";
const char* password = "$ArLimaHas";
void setup()
{
  Serial.begin(115200);
  Serial.println();
  Serial.println("Setting Wi-Fi Mode..");
  WiFi.mode(WIFI_STA);  //Set Wi-Fi mode as station 
  WiFi.begin(ssid, password); //Begin Connection
  Serial.println("Connecting to ");
  Serial.print(ssid);
  while(WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.print("Connected, IP address: ");
  Serial.println(WiFi.localIP()); //Display IP assigned by Wi-Fi Router
}
void loop()
{
  Serial.printf("Signal Strength in dB = %d\n", WiFi.RSSI());
  delay(3000);
}

After uploading a sketch, open serial your monitor. It will show connection status and Wi-Fi signal strength.

Wi-Fi Access Point ESP8266


≡ Wi-Fi Network Scan


ESP8266 NodeMCU Wi-Fi Scanner allows you to simply locate visible wireless networks and their similar information. in This program receives the network name (SSID), signal strength (RSSI) and MAC Address, security.  Wi-Fi scanner can only begin when NodeMCU is not connected to any network. 

#include <ESP8266WiFi.h>
void setup() {
  Serial.begin(115200);
  Serial.println(""); //Remove garbage
  // Set Wi-Fi to station mode and disconnect from an AP if it was previously connecte
  WiFi.mode(WIFI_STA);
//ESP has tendency to store old SSID and PASSword and tries to connect
  WiFi.disconnect(); 
  delay(100);
  Serial.println("Wi-Fi Network Scan Started")
}
void loop() {
 // WiFi.scanNetworks will return the number of networks found
  int n = WiFi.scanNetworks();
  Serial.println("Scan done");
  if (n == 0)
    Serial.println("No Networks Found");
  else
  {
    Serial.print(n);
    Serial.println(" Networks found");
    for (int i = 0; i < n; ++i)
    {
      // Print SSID and RSSI for each network found
      Serial.print(i + 1);  //Sr. No
      Serial.print(": ");
      Serial.print(WiFi.SSID(i)); //SSID
      Serial.print(" (");
     Serial.print(WiFi.RSSI(i)); //Signal Strength
      Serial.print(") MAC:");
      Serial.print(WiFi.BSSIDstr(i)); //Display MAC address of Wi-Fi Router
      Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" Unsecured":" Secured"); //Display Security
      delay(10);
    }
  }
  Serial.println("");
  // Wait a bit before starting New scanning again
  delay(5000);
}

Upload sketch and open serial monitor.

Wi-Fi Access Point ESP8266

Visit to get more tutorials on ESP8266

 203 total views,  5 views today