Go Down

Topic: How to turn off or stop Access Point network in ESP8266? (Read 55 times) previous topic - next topic

wBB

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", yet the Access Point network is also created.

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 192.168.1.1), 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:

Code: [Select]
#include <ESP8266WiFi.h>

bool access_point_init(){
    // Access Point Mode

   Serial.begin(115200);
   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
    Serial.begin(115200);
   Serial.printf("\n");

   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)){
      delay(250);
      Serial.print('.');
      k++;
   }

   Serial.printf("\n");
   Serial.printf("IP address: ");
   Serial.println(WiFi.localIP());
}


void setup()
{
    bool my_condition = false;
    //...
    // my_condition = myLoadFunction();
    //...

   if (my_condition) {
        access_point_init();
   } else {
      wifi_station_init();
   }
}

wBB

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

Code: [Select]
WiFi.softAPdisconnect (true);

Reference: softapdisconnect

 8)

Go Up