I've created a code for ESP8266 12E with Arduino IDE, in which it'll operate as "Station Mode" or "Access Point Mode" on Wifi, depending on the situation. Everything works fine except when device was configured as Access Point, even when I turn off device and then turn on again and force the Wifi initialization as "Station Mode", the Access Point network stays active.

Example: Let's suppose that I turned on the ESP8266 and initialized the Wifi as Access Point, and named the wifi network as "MY_WIFI_TEST". Let's assume now that I turned off the ESP8266 and forced it to turn on as "Station Mode". The ESP8266 typically connects to my network (the network of my gateway router, but keeps the network "MY_WIFI_TEST" active (the prior network as access point). You can not connect to this network, but it remains active.

How can I turn off or stop Access Point network?

My test code:

    #include <ESP8266WiFi.h>
    bool access_point_init(){
        // Access Point Mode
       IPAddress ip(192,168,1,254);
       IPAddress gateway(192,168,1,1);
       IPAddress subnet(255,255,255,0);
       char* ssid     = "myssidname";
       char* password = "12345678";
       WiFi.softAPConfig(ip, gateway, subnet);
       bool ret = WiFi.softAP(ssid, password);
       return ret;
    void wifi_station_init(){
        // Station Mode
       WiFi.begin(net_ssid, net_pwd_ssid);
       IPAddress ip(192,168,1,10);
       IPAddress gateway(192,168,1,1);
       IPAddress subnet(255,255,255,0); 
        WiFi.config(ip, gateway, subnet);
       k = 0;
       while ((WiFi.status() != WL_CONNECTED) && (k < 80)){
       Serial.printf("IP address: ");
    void setup() 
        bool my_condition = false;
        // my_condition = myLoadFunction();
       if (my_condition) { 
       } else {

3 Answers 3


I've already solved, by using a function of the library Wifi, specific for the connections in "Access Point" mode:

WiFi.softAPdisconnect (true);

Reference: softapdisconnect


I fixed this by adding below command before starting the accesspoint.



I was trying to turn off the softAP in the new Arduino Uno R4 Wifi so I could rename it and restart it. I put a changing sensor reading in AP name so I can see the value of it by just doing a network scan without actually connecting to it.

The wifi.h lib for UNO R4 doesn't implement SOFTAPDISCONNECT. In the example AP_SIMPLEWEB server I found adding the following function shuts down the AP and allows restarting with a different name.

void endAccessPoint() {
  using namespace std;
  string res = "";
  modem.write(string(PROMPT(_DISCONNECTSOFTAP)),res,"%s%d\r\n" ,CMD_WRITE(_DISCONNECTSOFTAP),1);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.