In this tutorial we see how to turn off ESP8266 WiFi, There are two methods to turn off wifi first is to use simple ESP8266WiFi.h Library and use WiFi.mode(WIFI_OFF); and another method to use WiFi.forceSleepBegin(); By turning wifi off you can save some power. or using only (WIFI_STA) station mode you can hide ESPs own Access point.
ESP8266 WiFi Example Code
/* * https://circuits4you.com * Turn off ESP8266 WiFi * */ #include <ESP8266WiFi.h> //======================================================================= // Power on setup //======================================================================= void setup() { delay(1000); Serial.begin(19200); Serial.println("Turning WiFi Off"); //WiFi.mode(WIFI_AP); //To Turn on WiFi in Specific Mode like WIFI_STA or WIFI_AP //Turn off WiFi WiFi.mode(WIFI_OFF); //This also works //WiFi.forceSleepBegin(); //This also works // WiFi.mode(WIFI_AP); //This line hides the viewing of ESP as wifi network // WiFi.begin(ssid, password); } //======================================================================= // Main Program Loop //======================================================================= void loop() { } //=========================================================================
You control WiFi using wifi.setmode()
. ESP8266’s WiFi is very versatile. You can be a client and/or an access point. You can get your IP from DHCP or static.
Per default, ESP8266 start in STATION_AP mode (as client and access point).
wifi.setmode()
Configures the WiFi mode to use. NodeMCU can run in one of four WiFi modes:
- Station mode (WIFI_STA), where the NodeMCU device joins an existing network
- Access point (WIFI_AP) mode, where it creates its own network that others can join
- Station + AP mode (WIFI_AP_STA), where it both creates its own network while at the same time being joined to another existing network
- WiFi off (WIFI_OFF)
When using the combined Station + AP mode, the same channel will be used for both networks as the radio can only listen on a single channel.
Note
WiFi configuration will be retained until changed even if device is turned off.
Syntax
wifi.setmode(mode[, save])
--Resume wifi from timed or indefinite sleep
wifi.resume()
Results
In below picture you will see Before turning off wifi and after turning off wifi scan results
- Before turning WiFi Off it shows ESP_47A070 MAC address last six digits.
- After Turning WiFi Off