Experiment-8 : To configure nodeMCU ESP8266 12-E in station mode IoT Experiments by Ravinder Nath Rajotiya - November 4, 2024November 4, 20240 Share on Facebook Share Send email Mail Print Print Table of Contents Toggle AIM : To configure nodeMCU ESP8266 12-E in station mode, and indicate the connected status on the LED.Objective:Requirement:Theory:Mode of Operation of ESP8266 –Station (STA) ModeOnce you have programmed ESP8266 in STA mode and you are successfully connected to stable WiFi, you can access any web page on the internet. Configuring ESP8266 in Station ModeOutput:Summary :Viva Questions: AIM : To configure nodeMCU ESP8266 12-E in station mode, and indicate the connected status on the LED. Objective: To configure ESP8266 as a station To establish communication between Access point and the station nodeMCU ESP8266 station. To blink the LED while searching for SSID and continuously glow when connected Requirement: Breadboard NodeMCU ESP8266 12-E One LED to indicate connected status One 220 Ohm Resistor Theory: Mode of Operation of ESP8266 – nodeMCU ESP8266 can operate in the following modes: ESP 8266 nodeMCU in station Mode Station (STA) Only Soft Access Point (Soft AP) Both the Soft Access Point and Station (Soft AP +STA) To play around with the ESP8266 WiFi module, you can program it in two modes: Station (STA) or Access Point (AP). Station (STA) Mode In station mode, ESP8266 will act just like your smartphone or laptop. It will connect to an existing WiFi channel, or in most cases, the WiFi advertised by your router. Once you have programmed ESP8266 in STA mode and you are successfully connected to stable WiFi, you can access any web page on the internet. Configuring ESP8266 in Station Mode In station Mode, we need to assign our Access Point (AP) or mobile Hot-spot SSID and password to the ESP8266 code. The station when uploaded with the code will search for the SSID of the hot-spot and if connected will show the status as connected. ESP8266 AP station /* The code below when uploaded on the ESP8266 will search for the SSID of */ /* * This code will configure ESP8266 in station mode, once uploaded will connect with a WiFi access point / mobile hot-spot. */ #include <ESP8266WiFi.h> //Here we specify the SSID and Password of the Local WiFi Network or hotspot const char* ssid = “moto”; //“localNetwork_wifi_ssid” const char* password = “12345678”; //”your_wifi_password” uint8_t retries=0; void setup() { //Start the serial communication with the computer pinMode(D1, OUTPUT); Serial.begin(115200); delay(100); Serial.println(); //Try and Connect to the Network WiFi.begin(ssid,password); Serial.print(“Connecting to “); Serial.print(ssid); Serial.println(“…”); //Wait for WiFi to connect for a maximum timeout of 20 seconds while(WiFi.status()!=WL_CONNECTED && retries<20) { Serial.print(“.”); digitalWrite(D1, HIGH); //Blink LED to indicate searching WiFi delay(100); digitalWrite(D1, LOW); delay(100); retries++; delay(500); } Serial.println(); //Inform the user whether the timeout has occured, if(retries= =20) //Timeout has occured { Serial.print(“Unable to Connect to “); Serial.println(ssid); digitalWrite(D2, HIGH); // red LED to indicate network not available } //Check if ESP8266 is connected to the local network WiFi access point } void loop() { // Maintain your WiFi connection by checking its status before performing any internet related task if (WiFi.status()==WL_CONNECTED) { //EP8266 is connected to WiFi Access Point. You can access Internet or any Web Server Serial.println(“Connected…”); digitalWrite(D1, HIGH); // status Green LED ON delay(1000); } else { //ESP8266 is not connected to any WiFi network. //You need to wait for the connection before you start interacting with any web server Serial.print(“Trying to connect with “); Serial.print(ssid); while(WiFi.status()!=WL_CONNECTED) { Serial.print(“.”); digitalWrite(D2, HIGH); //Red LED on to indicate no network delay(1000); } Serial.println(); Serial.print(“Sucessfully Connected to “); Serial.println(ssid); Serial.print(“IP Address: “); Serial.println(WiFi.localIP()); } } Output: Observe the status LED green and red to indicate network status. The green LED blinks during network SSID search and then turns continuously ON after establishing connection. The red LED will turn on if no network established. Status of connection is also displayed on the serial Monitor. Summary : In this experiment we learnt how to configure ESP8266 nodeMCU in station mode and the working of a station when connecting to a hotspot(Access point) by blinking the RED and GREEN LEDs Viva Questions: Briefly explain three mode of operation of the ESP8266 Write the steps involved in writing code for ESP8266 as a station. Explain the use of the conditional statements while(WiFi.status() !=WL_CONNECTED){…..} Share on Facebook Share Send email Mail Print Print