[GH-ISSUE #755] default AP mode after restart AutoConnectWithFSParameters #631

Closed
opened 2026-02-28 01:26:18 +03:00 by kerem · 2 comments
Owner

Originally created by @scropion86 on GitHub (Oct 15, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/755

PLEASE TRY DEVELOPMENT BRANCH before submitting bugs on release or master, in case they were already fixed.

POST SERIAL OUTPUT !

Issues without basic info will be ignored or closed!

Please fill the info fields, it helps to get you faster support ;)

if you have a stack dump decode it:
https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/stack_dump.rst

for better debug messages:
https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/debugging.rst

----------------------------- Remove above -----------------------------

Basic Infos

Hardware

WiFimanager Branch/Release:

  • Master
  • Development commit 2d021bb

Esp8266/Esp32:

  • ESP8266
  • ESP32

Hardware: ESP-12e, esp01, esp25

  • ESP01
  • ESP12 E/F/S (nodemcu, wemos, feather)
  • Other

ESP Core Version: 2.4.0, staging

  • 2.3.0
  • 2.4.0
  • staging (master/dev)
  • 2.4.2

Description

after filling the wifi details and add the additional parameters and save , the device restarts in AP mode
with SSID ESP_[chip_ID] which is not desired behavior
note i have cleared loop and re flashed same result

Settings in IDE

[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
upload_speed = 115200
monitor_speed = 115200
build_flags = -eagle.flash.4m.ld

Module: customized PCB with esp12F

Additional libraries:

Sketch

#include <FS.h>          // this needs to be first, or it all crashes and burns...
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson

#ifdef ESP32
  #include <SPIFFS.h>
#endif



//define your default values here, if there are different values in config.json, they are overwritten.
char Blynk_Server[40]= "10.0.1.56";
char Blynk_port[6]  = "8080";
char Main_Auth_token[32] = "YOUR_Main_Auth_token";
char Auth_Token_1[32] = "Auth_Token_1";
char Auth_Token_2[32] = "Auth_Token_2";
char Auth_Token_3[32] = "Auth_Token_3";
char Auth_Token_4[32] = "Auth_Token_4";
char Auth_Token_5[32] = "Auth_Token_5";
char Auth_Token_6[32] = "Auth_Token_6";



//default custom static IP
char static_ip[16] = "10.0.1.56";
char static_gw[16] = "10.0.1.1";
char static_sn[16] = "255.255.255.0";

//flag for saving data
bool shouldSaveConfig = false;

//callback notifying us of the need to save config
void saveConfigCallback () {
  Serial.println("Should save config");
  shouldSaveConfig = true;
}

void setupSpiffs(){
  
  //clean FS, for testing
  //SPIFFS.format();
  //Serial.println("Spiff Formatted");


  //read configuration from FS json
  Serial.println("mounting FS...");

  if (SPIFFS.begin()) {
    Serial.println("mounted file system");
    if (SPIFFS.exists("/config.json")) {
      //file exists, reading and loading
      Serial.println("reading config file");
      File configFile = SPIFFS.open("/config.json", "r");
      if (configFile) {
        Serial.println("opened config file");
        size_t size = configFile.size();
        // Allocate a buffer to store contents of the file.
        std::unique_ptr<char[]> buf(new char[size]);

        configFile.readBytes(buf.get(), size);
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject(buf.get());
        json.printTo(Serial);
        if (json.success()) {
          Serial.println("\nparsed json");

          strcpy(Blynk_Server, json["Blynk_Server"]);
          strcpy(Blynk_port, json["Blynk_port"]);
          strcpy(Main_Auth_token, json["Main_Auth_token"]);
          strcpy(Auth_Token_1, json["Auth_Token_1"]);
          strcpy(Auth_Token_2, json["Auth_Token_2"]);
          strcpy(Auth_Token_3, json["Auth_Token_3"]);
          strcpy(Auth_Token_4, json["Auth_Token_4"]);
          strcpy(Auth_Token_5, json["Auth_Token_5"]);
          strcpy(Auth_Token_6, json["Auth_Token_6"]);



          // if(json["ip"]) {
          //   Serial.println("setting custom ip from config");
          //   strcpy(static_ip, json["ip"]);
          //   strcpy(static_gw, json["gateway"]);
          //   strcpy(static_sn, json["subnet"]);
          //   Serial.println(static_ip);
          // } else {
          //   Serial.println("no custom ip in config");
          // }

        } else {
          Serial.println("failed to load json config");
        }
      }
    }
  } else {
    Serial.println("failed to mount FS");
  }
  //end read
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println();

  setupSpiffs();
    

  // WiFiManager, Local intialization. Once its business is done, there is no need to keep it around (disabled and moved to start for non blocking)
    WiFiManager wm;
    // invert colors black theme
    wm.setClass("invert");

  //set config save notify callback
  wm.setSaveConfigCallback(saveConfigCallback);

  // setup custom parameters
  // 
  // The extra parameters to be configured (can be either global or just in the setup)
  // After connecting, parameter.getValue() will get you the configured value
  // id/name placeholder/prompt default length
  WiFiManagerParameter custom_Blynk_Server("server", "Blynk server", Blynk_Server, 40);
  WiFiManagerParameter custom_Blynk_port("port", "Blynk port", Blynk_port, 6);
  WiFiManagerParameter custom_Main_Auth_token("Token", "Main Auth token", "", 32);
  WiFiManagerParameter custom_Auth_Token_1("Token1", "Auth token 1", "", 32);
  WiFiManagerParameter custom_Auth_Token_2("Token2", "Auth token 2", "", 32);
  WiFiManagerParameter custom_Auth_Token_3("Token3", "Auth token 3", "", 32);
  WiFiManagerParameter custom_Auth_Token_4("Token4", "Auth token 4", "", 32);
  WiFiManagerParameter custom_Auth_Token_5("Token5", "Auth token 5", "", 32);
  WiFiManagerParameter custom_Auth_Token_6("Token6", "Auth token 6", "", 32);







  //add all your parameters here
  wm.addParameter(&custom_Blynk_Server);
  wm.addParameter(&custom_Blynk_port);
  wm.addParameter(&custom_Main_Auth_token);
  wm.addParameter(&custom_Auth_Token_1);
  wm.addParameter(&custom_Auth_Token_2);
  wm.addParameter(&custom_Auth_Token_3);
  wm.addParameter(&custom_Auth_Token_4);
  wm.addParameter(&custom_Auth_Token_5);
  wm.addParameter(&custom_Auth_Token_6);



  // set static ip
  // IPAddress _ip,_gw,_sn;
  // _ip.fromString(static_ip);
  // _gw.fromString(static_gw);
  // _sn.fromString(static_sn);
  // wm.setSTAStaticIPConfig(_ip, _gw, _sn);

  //reset settings - wipe credentials for testing
  //wm.resetSettings();

  //automatically connect using saved credentials if they exist
  //If connection fails it starts an access point with the specified name
  //here  "AutoConnectAP" if empty will auto generate basedcon chipid, if password is blank it will be anonymous
  //and goes into a blocking loop awaiting configuration
  if (!wm.autoConnect("AutoConnectAP", "password")) {
    Serial.println("failed to connect and hit timeout");
    delay(3000);
    // if we still have not connected restart and try all over again
    ESP.restart();
    delay(5000);
  }



  // always start configportal for a little while
  // wm.setConfigPortalTimeout(60);
  // wm.startConfigPortal("AutoConnectAP","password");

  //if you get here you have connected to the WiFi
  Serial.println("connected...yeey :)");

  //read updated parameters
  strcpy(Blynk_Server, custom_Blynk_Server.getValue());
  strcpy(Blynk_port, custom_Blynk_port.getValue());
  strcpy(Main_Auth_token, custom_Main_Auth_token.getValue());
  strcpy(Auth_Token_1, custom_Auth_Token_1.getValue());
  strcpy(Auth_Token_2, custom_Auth_Token_2.getValue());
  strcpy(Auth_Token_3, custom_Auth_Token_3.getValue());
  strcpy(Auth_Token_4, custom_Auth_Token_4.getValue());
  strcpy(Auth_Token_5, custom_Auth_Token_5.getValue());
  strcpy(Auth_Token_6, custom_Auth_Token_6.getValue());





  //save the custom parameters to FS
  if (shouldSaveConfig) {
    Serial.println("saving config");
    DynamicJsonBuffer jsonBuffer;
    JsonObject& json = jsonBuffer.createObject();
    json["Blynk_Server"] = Blynk_Server;
    json["Blynk_port"]   = Blynk_port;
    json["Main_Auth_token"]   = Main_Auth_token;
    json["Auth_Token_1"]   = Auth_Token_1;
    json["Auth_Token_2"]   = Auth_Token_2;
    json["Auth_Token_3"]   = Auth_Token_3;
    json["Auth_Token_4"]   = Auth_Token_4;
    json["Auth_Token_5"]   = Auth_Token_5;
    json["Auth_Token_6"]   = Auth_Token_6;


    // json["ip"]          = WiFi.localIP().toString();
    // json["gateway"]     = WiFi.gatewayIP().toString();
    // json["subnet"]      = WiFi.subnetMask().toString();

    File configFile = SPIFFS.open("/config.json", "w");
    if (!configFile) {
      Serial.println("failed to open config file for writing");
    }

    json.prettyPrintTo(Serial);
    json.printTo(configFile);
    configFile.close();
    //end save
    shouldSaveConfig = false;
  }

  Serial.println("local ip");
  Serial.println(WiFi.localIP());
  Serial.println(WiFi.gatewayIP());
  Serial.println(WiFi.subnetMask());
}

void loop() {

  // put your main code here, to run repeatedly:


}


Debug Messages

rl␀l��|␀�l�|␂␌␌␌�␌l�␌b|��␂�␒�r�b�␌b��nn�lnn���␌b␜p��lrlrlp�n�␐␂␌␌�␌l␌��␌␌␌b␌n�|␂l�␌␌�b��nn�␀l��l`␂�␒␒nn␌l`␂␎␂nr���n␌␌b␌�␎l␎r��n␌␌b␌�␎l�bbb␌␌���l`␂��n�␂
mounting FS...
mounted file system
reading config file
opened config file
{"Blynk_Server":"10.0.1.56","Blynk_port":"8080","Main_Auth_token":" 8080 Main Auth token","Auth_Token_1":" Auth token 1","Auth_Token_2":" Auth token 2","Auth_Token_3":" Auth token 3","Auth_Token_4":" Auth token 4","Auth_Token_5":" Auth token 5","Auth_Token_6":" Auth token 6"}
parsed json
*WM: [3] allocating params bytes: 20
*WM: [2] Added Parameter: server
*WM: [2] Added Parameter: port
*WM: [2] Added Parameter: Token
*WM: [2] Added Parameter: Token1
*WM: [2] Added Parameter: Token2
*WM: [3] Updated _max_params: 10
*WM: [3] re-allocating params bytes: 40
*WM: [2] Added Parameter: Token3
*WM: [2] Added Parameter: Token4
*WM: [2] Added Parameter: Token5
*WM: [2] Added Parameter: Token6
*WM: [1] AutoConnect
*WM: [2] Connecting as wifi client...
*WM: [2] setSTAConfig static ip not set
*WM: [3] WIFI station disconnect
*WM: [1] Connecting to saved AP: MoHaMeD
*WM: [3] WiFi station enable
*WM: [3] enableSTA PERSISTENT ON
*WM: [1] connectTimeout not set, ESP waitForConnectResult...
*WM: [2] Connection result: WL_CONNECTED
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [1] AutoConnect: SUCCESS
*WM: [1] STA IP Address: 192.168.1.43
connected...yeey :)
local ip
192.168.1.43
192.168.1.254
255.255.255.0
*WM: [3] freeing allocated params!
*WM: [3] unloading

Originally created by @scropion86 on GitHub (Oct 15, 2018). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/755 ## PLEASE TRY DEVELOPMENT BRANCH before submitting bugs on release or master, in case they were already fixed. ## ## POST SERIAL OUTPUT ! Issues without basic info will be ignored or closed! Please fill the info fields, it helps to get you faster support ;) if you have a stack dump decode it: https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/stack_dump.rst for better debug messages: https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/debugging.rst ----------------------------- Remove above ----------------------------- ### Basic Infos #### Hardware **WiFimanager Branch/Release:** - [ ] Master - [x] Development commit 2d021bb **Esp8266/Esp32:** - [x] ESP8266 - [ ] ESP32 **Hardware: ESP-12e, esp01, esp25** - [ ] ESP01 - [x] ESP12 E/F/S (nodemcu, wemos, feather) - [ ] Other **ESP Core Version: 2.4.0, staging** - [ ] 2.3.0 - [ ] 2.4.0 - [ ] staging (master/dev) - [x] 2.4.2 ### Description after filling the wifi details and add the additional parameters and save , the device restarts in AP mode with SSID ESP_[chip_ID] which is not desired behavior note i have cleared loop and re flashed same result ### Settings in IDE [env:esp12e] platform = espressif8266 board = esp12e framework = arduino upload_speed = 115200 monitor_speed = 115200 build_flags = -eagle.flash.4m.ld Module: customized PCB with esp12F Additional libraries: ### Sketch ```cpp #include <FS.h> // this needs to be first, or it all crashes and burns... #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager #include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson #ifdef ESP32 #include <SPIFFS.h> #endif //define your default values here, if there are different values in config.json, they are overwritten. char Blynk_Server[40]= "10.0.1.56"; char Blynk_port[6] = "8080"; char Main_Auth_token[32] = "YOUR_Main_Auth_token"; char Auth_Token_1[32] = "Auth_Token_1"; char Auth_Token_2[32] = "Auth_Token_2"; char Auth_Token_3[32] = "Auth_Token_3"; char Auth_Token_4[32] = "Auth_Token_4"; char Auth_Token_5[32] = "Auth_Token_5"; char Auth_Token_6[32] = "Auth_Token_6"; //default custom static IP char static_ip[16] = "10.0.1.56"; char static_gw[16] = "10.0.1.1"; char static_sn[16] = "255.255.255.0"; //flag for saving data bool shouldSaveConfig = false; //callback notifying us of the need to save config void saveConfigCallback () { Serial.println("Should save config"); shouldSaveConfig = true; } void setupSpiffs(){ //clean FS, for testing //SPIFFS.format(); //Serial.println("Spiff Formatted"); //read configuration from FS json Serial.println("mounting FS..."); if (SPIFFS.begin()) { Serial.println("mounted file system"); if (SPIFFS.exists("/config.json")) { //file exists, reading and loading Serial.println("reading config file"); File configFile = SPIFFS.open("/config.json", "r"); if (configFile) { Serial.println("opened config file"); size_t size = configFile.size(); // Allocate a buffer to store contents of the file. std::unique_ptr<char[]> buf(new char[size]); configFile.readBytes(buf.get(), size); DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.parseObject(buf.get()); json.printTo(Serial); if (json.success()) { Serial.println("\nparsed json"); strcpy(Blynk_Server, json["Blynk_Server"]); strcpy(Blynk_port, json["Blynk_port"]); strcpy(Main_Auth_token, json["Main_Auth_token"]); strcpy(Auth_Token_1, json["Auth_Token_1"]); strcpy(Auth_Token_2, json["Auth_Token_2"]); strcpy(Auth_Token_3, json["Auth_Token_3"]); strcpy(Auth_Token_4, json["Auth_Token_4"]); strcpy(Auth_Token_5, json["Auth_Token_5"]); strcpy(Auth_Token_6, json["Auth_Token_6"]); // if(json["ip"]) { // Serial.println("setting custom ip from config"); // strcpy(static_ip, json["ip"]); // strcpy(static_gw, json["gateway"]); // strcpy(static_sn, json["subnet"]); // Serial.println(static_ip); // } else { // Serial.println("no custom ip in config"); // } } else { Serial.println("failed to load json config"); } } } } else { Serial.println("failed to mount FS"); } //end read } void setup() { // put your setup code here, to run once: Serial.begin(115200); Serial.println(); setupSpiffs(); // WiFiManager, Local intialization. Once its business is done, there is no need to keep it around (disabled and moved to start for non blocking) WiFiManager wm; // invert colors black theme wm.setClass("invert"); //set config save notify callback wm.setSaveConfigCallback(saveConfigCallback); // setup custom parameters // // The extra parameters to be configured (can be either global or just in the setup) // After connecting, parameter.getValue() will get you the configured value // id/name placeholder/prompt default length WiFiManagerParameter custom_Blynk_Server("server", "Blynk server", Blynk_Server, 40); WiFiManagerParameter custom_Blynk_port("port", "Blynk port", Blynk_port, 6); WiFiManagerParameter custom_Main_Auth_token("Token", "Main Auth token", "", 32); WiFiManagerParameter custom_Auth_Token_1("Token1", "Auth token 1", "", 32); WiFiManagerParameter custom_Auth_Token_2("Token2", "Auth token 2", "", 32); WiFiManagerParameter custom_Auth_Token_3("Token3", "Auth token 3", "", 32); WiFiManagerParameter custom_Auth_Token_4("Token4", "Auth token 4", "", 32); WiFiManagerParameter custom_Auth_Token_5("Token5", "Auth token 5", "", 32); WiFiManagerParameter custom_Auth_Token_6("Token6", "Auth token 6", "", 32); //add all your parameters here wm.addParameter(&custom_Blynk_Server); wm.addParameter(&custom_Blynk_port); wm.addParameter(&custom_Main_Auth_token); wm.addParameter(&custom_Auth_Token_1); wm.addParameter(&custom_Auth_Token_2); wm.addParameter(&custom_Auth_Token_3); wm.addParameter(&custom_Auth_Token_4); wm.addParameter(&custom_Auth_Token_5); wm.addParameter(&custom_Auth_Token_6); // set static ip // IPAddress _ip,_gw,_sn; // _ip.fromString(static_ip); // _gw.fromString(static_gw); // _sn.fromString(static_sn); // wm.setSTAStaticIPConfig(_ip, _gw, _sn); //reset settings - wipe credentials for testing //wm.resetSettings(); //automatically connect using saved credentials if they exist //If connection fails it starts an access point with the specified name //here "AutoConnectAP" if empty will auto generate basedcon chipid, if password is blank it will be anonymous //and goes into a blocking loop awaiting configuration if (!wm.autoConnect("AutoConnectAP", "password")) { Serial.println("failed to connect and hit timeout"); delay(3000); // if we still have not connected restart and try all over again ESP.restart(); delay(5000); } // always start configportal for a little while // wm.setConfigPortalTimeout(60); // wm.startConfigPortal("AutoConnectAP","password"); //if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); //read updated parameters strcpy(Blynk_Server, custom_Blynk_Server.getValue()); strcpy(Blynk_port, custom_Blynk_port.getValue()); strcpy(Main_Auth_token, custom_Main_Auth_token.getValue()); strcpy(Auth_Token_1, custom_Auth_Token_1.getValue()); strcpy(Auth_Token_2, custom_Auth_Token_2.getValue()); strcpy(Auth_Token_3, custom_Auth_Token_3.getValue()); strcpy(Auth_Token_4, custom_Auth_Token_4.getValue()); strcpy(Auth_Token_5, custom_Auth_Token_5.getValue()); strcpy(Auth_Token_6, custom_Auth_Token_6.getValue()); //save the custom parameters to FS if (shouldSaveConfig) { Serial.println("saving config"); DynamicJsonBuffer jsonBuffer; JsonObject& json = jsonBuffer.createObject(); json["Blynk_Server"] = Blynk_Server; json["Blynk_port"] = Blynk_port; json["Main_Auth_token"] = Main_Auth_token; json["Auth_Token_1"] = Auth_Token_1; json["Auth_Token_2"] = Auth_Token_2; json["Auth_Token_3"] = Auth_Token_3; json["Auth_Token_4"] = Auth_Token_4; json["Auth_Token_5"] = Auth_Token_5; json["Auth_Token_6"] = Auth_Token_6; // json["ip"] = WiFi.localIP().toString(); // json["gateway"] = WiFi.gatewayIP().toString(); // json["subnet"] = WiFi.subnetMask().toString(); File configFile = SPIFFS.open("/config.json", "w"); if (!configFile) { Serial.println("failed to open config file for writing"); } json.prettyPrintTo(Serial); json.printTo(configFile); configFile.close(); //end save shouldSaveConfig = false; } Serial.println("local ip"); Serial.println(WiFi.localIP()); Serial.println(WiFi.gatewayIP()); Serial.println(WiFi.subnetMask()); } void loop() { // put your main code here, to run repeatedly: } ``` ### Debug Messages ``` rl␀l��|␀�l�|␂␌␌␌�␌l�␌b|��␂�␒�r�b�␌b��nn�lnn���␌b␜p��lrlrlp�n�␐␂␌␌�␌l␌��␌␌␌b␌n�|␂l�␌␌�b��nn�␀l��l`␂�␒␒nn␌l`␂␎␂nr���n␌␌b␌�␎l␎r��n␌␌b␌�␎l�bbb␌␌���l`␂��n�␂ mounting FS... mounted file system reading config file opened config file {"Blynk_Server":"10.0.1.56","Blynk_port":"8080","Main_Auth_token":" 8080 Main Auth token","Auth_Token_1":" Auth token 1","Auth_Token_2":" Auth token 2","Auth_Token_3":" Auth token 3","Auth_Token_4":" Auth token 4","Auth_Token_5":" Auth token 5","Auth_Token_6":" Auth token 6"} parsed json *WM: [3] allocating params bytes: 20 *WM: [2] Added Parameter: server *WM: [2] Added Parameter: port *WM: [2] Added Parameter: Token *WM: [2] Added Parameter: Token1 *WM: [2] Added Parameter: Token2 *WM: [3] Updated _max_params: 10 *WM: [3] re-allocating params bytes: 40 *WM: [2] Added Parameter: Token3 *WM: [2] Added Parameter: Token4 *WM: [2] Added Parameter: Token5 *WM: [2] Added Parameter: Token6 *WM: [1] AutoConnect *WM: [2] Connecting as wifi client... *WM: [2] setSTAConfig static ip not set *WM: [3] WIFI station disconnect *WM: [1] Connecting to saved AP: MoHaMeD *WM: [3] WiFi station enable *WM: [3] enableSTA PERSISTENT ON *WM: [1] connectTimeout not set, ESP waitForConnectResult... *WM: [2] Connection result: WL_CONNECTED *WM: [3] lastconxresult: WL_CONNECTED *WM: [1] AutoConnect: SUCCESS *WM: [1] STA IP Address: 192.168.1.43 connected...yeey :) local ip 192.168.1.43 192.168.1.254 255.255.255.0 *WM: [3] freeing allocated params! *WM: [3] unloading ```
kerem closed this issue 2026-02-28 01:26:18 +03:00
Author
Owner

@tablatronix commented on GitHub (Oct 15, 2018):

That is the default behavior of esp8266, you have to set your own mode in your code.

try setup()
WiFi.mode(WIFI_STA);

<!-- gh-comment-id:429961261 --> @tablatronix commented on GitHub (Oct 15, 2018): That is the default behavior of esp8266, you have to set your own mode in your code. try setup() `WiFi.mode(WIFI_STA);`
Author
Owner

@scropion86 commented on GitHub (Oct 16, 2018):

Thank's , i will re-try with your suggestion .

<!-- gh-comment-id:430104046 --> @scropion86 commented on GitHub (Oct 16, 2018): Thank's , i will re-try with your suggestion .
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#631
No description provided.