NodeMCU V3 ESP8266
WiFi Modes of Operation of ESP8266: There are three modes of WiFi Operation in the ESP8266 WiFi Module. Those are:
- Station Mode (STA)
- Soft Access Point (AP)
- Soft AP + Station
Station Mode
Only Access Point
#include "ESP8266WiFi.h"
const char* ssid = "ChorkeOrg_2.4GHz";
const char* pass = "academia";
void setup(void) {
pinMode(D4, OUTPUT);
Serial.begin(115200);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print("*");
}
Serial.println("");
Serial.println("WiFi connection Successful");
Serial.print("The IP Address of ESP8266 Module is: ");
Serial.print(WiFi.localIP());
}
void loop() {
digitalWrite(D4, LOW);
delay(1000);
digitalWrite(D4, HIGH);
delay(1000);
}
Multi Access Point
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
const char* ap0_ssid_50 = "ChorkeOrg";
const char* ap0_pasword = "chorke@bd/0A";
const char* ap0_ssid_24 = "ChorkeOrg_2.4GHz";
ESP8266WiFiMulti multi;
void setup(void) {
pinMode(D4, OUTPUT);
Serial.begin(115200);
delay(10);
Serial.println('\n');
multi.addAP(ap0_ssid_24, ap0_pasword);
multi.addAP(ap0_ssid_50, ap0_pasword);
Serial.print("Connecting : ");
while (multi.run() != WL_CONNECTED) {
delay(500);
Serial.print('>');
}
Serial.println('\n');
Serial.print("Connected to: ");
Serial.println(WiFi.SSID());
Serial.print("IP address : ");
Serial.println(WiFi.localIP());
}
void loop() {
digitalWrite(D4, LOW);
delay(1000);
digitalWrite(D4, HIGH);
delay(1000);
}
Soft Access Point
#include "ESP8266WiFi.h"
const char* ssid = "ChorkeIot_2.4GHz";
const char* pass = "academia";
IPAddress local_IP(10, 19, 83, 10);
IPAddress subnet(255, 255, 255, 0);
IPAddress gateway(10, 19, 83, 1);
void setup(void) {
pinMode(D4, OUTPUT);
Serial.begin(115200);
Serial.println();
Serial.print("WNC Config: ");
Serial.print(WiFi.softAPConfig(local_IP, gateway, subnet) ? "Ready" : "Failed!");
Serial.println("SID Config: ");
Serial.print(WiFi.softAP(ssid, pass) ? "Ready" : "Failed!");
Serial.println("WAN Config: ");
Serial.print(WiFi.softAPIP());
}
void loop() {
digitalWrite(D4, LOW);
delay(1000);
digitalWrite(D4, HIGH);
delay(1000);
}
Duel Mode
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESP8266WiFiMulti.h>
const char* ssid = "ChorkeIot_2.4GHz";
const char* pass = "academia";
const char* ap0_ssid_50 = "ChorkeOrg";
const char* ap0_pasword = "chorke@bd/0A";
const char* ap0_ssid_24 = "ChorkeOrg_2.4GHz";
ESP8266WiFiMulti multi;
void setup(void) {
pinMode(D4, OUTPUT);
Serial.begin(115200);
delay(10);
Serial.println('\n');
multi.addAP(ap0_ssid_24, ap0_pasword);
multi.addAP(ap0_ssid_50, ap0_pasword);
Serial.print("Connecting: ");
while (multi.run() != WL_CONNECTED) {
delay(500);
Serial.print('>');
}
Serial.println('\n');
Serial.print("Connected : ");
Serial.println(WiFi.SSID());
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) {
Serial.println("DNS OK!");
}
Serial.print("WNC Config: ");
Serial.println(WiFi.softAPConfig(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask()) ? "Ready" : "Failed!");
Serial.print("SID Config: ");
Serial.println(WiFi.softAP(ssid, pass) ? "Ready" : "Failed!");
Serial.print("WAN Config: ");
Serial.println(WiFi.softAPIP());
}
void loop() {
digitalWrite(D4, LOW);
delay(1000);
digitalWrite(D4, HIGH);
delay(1000);
}
Web Server
#include <WiFiClient.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WebServer.h>
const char* ssid = "ChorkeIot_2.4GHz";
const char* pass = "academia";
const char* ap0_ssid_50 = "ChorkeOrg";
const char* ap0_pasword = "chorke@bd/0A";
const char* ap0_ssid_24 = "ChorkeOrg_2.4GHz";
ESP8266WiFiMulti multi;
ESP8266WebServer server(80);
void handleRoot();
void handleNotFound();
void setup(void) {
pinMode(D4, OUTPUT);
Serial.begin(115200);
delay(10);
Serial.println('\n');
multi.addAP(ap0_ssid_24, ap0_pasword);
multi.addAP(ap0_ssid_50, ap0_pasword);
Serial.print("Connecting: ");
while (multi.run() != WL_CONNECTED) {
delay(500);
Serial.print('>');
}
Serial.println('\n');
Serial.print("Connected : ");
Serial.println(WiFi.SSID());
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) {
Serial.println("DNS OK!");
}
server.on("/", handleRoot);
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
Serial.print("WNC Config: ");
Serial.println(WiFi.softAPConfig(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask()) ? "Ready" : "Failed!");
Serial.print("SID Config: ");
Serial.println(WiFi.softAP(ssid, pass) ? "Ready" : "Failed!");
Serial.print("WAN Config: ");
Serial.println(WiFi.softAPIP());
}
void loop() {
server.handleClient();
digitalWrite(D4, LOW);
delay(1000);
digitalWrite(D4, HIGH);
delay(1000);
}
void handleRoot() {
server.send(200, "text/plain", "Hello, Acadmeian!");
}
void handleNotFound() {
server.send(404, "text/plain", "404: Not found");
}