[GH-ISSUE #1706] ESP32 crashes when clicking on "Config WiFi" or "Setup" in webportal #1444

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

Originally created by @exc2k on GitHub (Jan 30, 2024).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1706

Hello, once I configurated and connected to my WiFI my ESP crashes when I open the webportal or the configportal again (while connected to wifi) and clicking on "Configurate WiFi" or "Setup". "Info" works well.

After it crashes it can't connect to my wifi anymore (authetication failure) and it goes into AP-Mode.

Platform and Env:

platform = espressif32
board = lolin32
framework = arduino
lib_deps = 
	wnatth3/WiFiManager@^2.0.16-rc.2
	bblanchon/ArduinoJson@^7.0.2

Console Output:

mounting FS...
mounted file system
reading config file
opened config file
{"mqtt_server":"Mymqtt","mqtt_port":"8080","api_token":"YOUR_API_TOKEN","ip":"192.168.2.168","gateway":"192.168.2.1","subnet":"255.255.255.0"}
parsed json
setting custom ip from config
192.168.2.168
192.168.2.168
YOUR_API_TOKEN
Mymqtt
*wm:AutoConnect
*wm:STA IP set: 192.168.2.168
*wm:Connecting to SAVED AP: Ikarus
*wm:connectTimeout not set, ESP waitForConnectResult... 
*wm:AutoConnect: SUCCESS 
*wm:STA IP Address: 192.168.2.168
connected...yeey :)
The values in the file are:
        mqtt_server : Mymqtt
        mqtt_port : 8080
        api_token : YOUR_API_TOKEN
local ip
192.168.2.168
192.168.2.1
255.255.255.0
starting config portal (on demand/non blocking) for troubleshooting for 120s
*wm:StartAP with SSID:  ESP32_6BCB94EC
*wm:AP IP address: 192.168.4.1
*wm:Starting Web Portal
starting web portal

**HERE I CLICK ON CONFIG WIFI IN WEBPORTAL (OR CONFIGPORTAL)**

*wm:11 networks found
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x40089e14  PS      : 0x00060f30  A0      : 0x800e234d  A1      : 0x3ffb1f30
A2      : 0x00000069  A3      : 0x00000065  A4      : 0x000000ff  A5      : 0x0000ff00  
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x800e2188  A9      : 0x3ffb1f00
A10     : 0x3ffb1f6c  A11     : 0x00000000  A12     : 0x00000014  A13     : 0x0000ff00  
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x00000018  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000069  LBEG    : 0x40089e35  LEND    : 0x40089e45  LCOUNT  : 0xfffffffa  


Backtrace: 0x40089e11:0x3ffb1f30 0x400e234a:0x3ffb1f40 0x400d8163:0x3ffb1f60 0x400d9dc9:0x3ffb1fa0 0x400decf2:0x3ffb2050 0x40166a59:0x3ffb20b0 0x400dbbbe:0x3ffb20d0 0x40155a5d:0x3ffb20f0 0x40155b3a:0x3ffb2130 0x40155cdd:0x3ffb21a0 0x400ddf36:0x3ffb21f0 0x400de13b:0x3ffb2250 0x400d3646:0x3ffb2270 0x400e3e75:0x3ffb2290

  #0  0x40089e11:0x3ffb1f30 in strlen at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/machine/xtensa/strlen.S:43
  #1  0x400e234a:0x3ffb1f40 in String::String(char const*) at C:/Users/dev/.platformio/packages/framework-arduinoespressif32/cores/esp32/WString.cpp:36
      (inlined by) String::String(char const*) at C:/Users/dev/.platformio/packages/framework-arduinoespressif32/cores/esp32/WString.cpp:33
  #2  0x400d8163:0x3ffb1f60 in String::replace(__FlashStringHelper const*, char const*) at C:/Users/dev/.platformio/packages/framework-arduinoespressif32/cores/esp32/WString.h:281
  #3  0x400d9dc9:0x3ffb1fa0 in WiFiManager::getParamOut() at .pio/libdeps/lolin32/WiFiManager/WiFiManager.cpp:1776 (discriminator 1)
  #4  0x400decf2:0x3ffb2050 in WiFiManager::handleWifi(bool) at .pio/libdeps/lolin32/WiFiManager/WiFiManager.cpp:1392
  #5  0x40166a59:0x3ffb20b0 in void std::__invoke_impl<void, void (WiFiManager::*&)(bool), WiFiManager*&, bool&>(std::__invoke_memfun_deref, void (WiFiManager::*&)(bool), WiFiManager*&, bool&) at c:\users\dev\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/invoke.h:73
      (inlined by) std::__invoke_result<void (WiFiManager::*&)(bool), WiFiManager*&, bool&>::type std::__invoke<void (WiFiManager::*&)(bool), WiFiManager*&, bool&>(void (WiFiManager::*&)(bool), WiFiManager*&, bool&) at c:\users\dev\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/invoke.h:95
      (inlined by) void std::_Bind<void (WiFiManager::*(WiFiManager*, bool))(bool)>::__call<void, , 0u, 1u>(std::tuple<>&&, std::_Index_tuple<0u, 1u>) at c:\users\dev\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0/functional:400
      (inlined by) void std::_Bind<void (WiFiManager::*(WiFiManager*, bool))(bool)>::operator()<, void>() at c:\users\dev\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0/functional:484
      (inlined by) std::_Function_handler<void (), std::_Bind<void (WiFiManager::*(WiFiManager*, bool))(bool)> >::_M_invoke(std::_Any_data const&) at c:\users\dev\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:297
  #6  0x400dbbbe:0x3ffb20d0 in std::function<void ()>::operator()() const at c:\users\dev\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:687
  #7  0x40155a5d:0x3ffb20f0 in FunctionRequestHandler::handle(WebServer&, http_method, String) at C:/Users/dev/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/detail/RequestHandlersImpl.h:45
  #8  0x40155b3a:0x3ffb2130 in WebServer::_handleRequest() at C:/Users/dev/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.cpp:651       
  #9  0x40155cdd:0x3ffb21a0 in WebServer::handleClient() at C:/Users/dev/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.cpp:318
  #10 0x400ddf36:0x3ffb21f0 in WiFiManager::processConfigPortal() at .pio/libdeps/lolin32/WiFiManager/WiFiManager.cpp:871
  #11 0x400de13b:0x3ffb2250 in WiFiManager::process() at .pio/libdeps/lolin32/WiFiManager/WiFiManager.cpp:851
  #12 0x400d3646:0x3ffb2270 in loop() at src/main.cpp:241
  #13 0x400e3e75:0x3ffb2290 in loopTask(void*) at C:/Users/dev/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:50

I also get sometime a lot of this when I navigate through the portal:

[ 11228][E][WebServer.cpp:648] _handleRequest(): request handler not found

My code is basically copied from your examples with a few changes:

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

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

#include <ArduinoJson.h>          //https://github.com/bblanchon/ArduinoJson





//======= DEFINITIONS ================================================================================
const char AP_name[10] = "AP-Config";              //Access Point name
const char AP_pw[16] = "12345678";                 //Access Point password



//define your default values here, if there are different values in config.json, they are overwritten.
char mqtt_server[40];
char mqtt_port[6] = "8080";
char api_token[34] = "YOUR_API_TOKEN";
char static_ip[16] = "192.168.2.169";
char static_gw[16] = "192.168.2.1";
char static_sn[16] = "255.255.255.0";


//flag for saving data
bool shouldSaveConfig = false;          //New Config
bool portalRunning = false;             //Run Webportal


//WiFiManager
//Global init to have it in loop available
WiFiManager wifiManager;



//======= FUNCTIONS ================================================================================

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




//======= VOID SETUP ================================================================================

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

  //clean FS, for testing
  //SPIFFS.format();

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

  if (!SPIFFS.begin()) {
    Serial.println("mounting filesystem failed.. trying to format");
    SPIFFS.format();
    Serial.println("trying again to mount 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);


        JsonDocument json;
        auto deserializeError = deserializeJson(json, buf.get());
        serializeJson(json, Serial);
        if (!deserializeError ) {
           Serial.println("\nparsed json");
           strcpy(mqtt_server, json["mqtt_server"]);
           strcpy(mqtt_port, json["mqtt_port"]);
           strcpy(api_token, json["api_token"]);

           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");
        }
        configFile.close();
      }
    }
  } else {
    Serial.println("failed to mount FS");
  }
  //end read


  Serial.println(static_ip);
  Serial.println(api_token);
  Serial.println(mqtt_server);



  // 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_mqtt_server("server", "mqtt server", mqtt_server, 40);
  WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 6);
  WiFiManagerParameter custom_api_token("apikey", "API token", api_token, 32);

  //set config save notify callback
  wifiManager.setSaveConfigCallback(saveConfigCallback);
  wifiManager.setBreakAfterConfig(true);

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

  wifiManager.setSTAStaticIPConfig(_ip, _gw, _sn);

  //add all your parameters here
  wifiManager.addParameter(&custom_mqtt_server);
  wifiManager.addParameter(&custom_mqtt_port);
  wifiManager.addParameter(&custom_api_token);

  //reset settings - for testing
  //wifiManager.resetSettings();

  //set minimu quality of signal so it ignores AP's under that quality
  //defaults to 8%
  //wifiManager.setMinimumSignalQuality();

  //sets timeout until configuration portal gets turned off
  //useful to make it all retry or go to sleep
  //in seconds
  wifiManager.setTimeout(300);

  //fetches ssid and pass and tries to connect
  //if it does not connect it starts an access point with the specified name
  //and goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect(AP_name, AP_pw)) {
    Serial.println("failed to connect and hit timeout");
    delay(3000);
    //reset and try again, or maybe put it to deep sleep
    ESP.restart();
    delay(5000);
  }

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

  //read updated parameters
  strcpy(mqtt_server, custom_mqtt_server.getValue());
  strcpy(mqtt_port, custom_mqtt_port.getValue());
  strcpy(api_token, custom_api_token.getValue());

  Serial.println("The values in the file are: ");
  Serial.println("\tmqtt_server : " + String(mqtt_server));
  Serial.println("\tmqtt_port : " + String(mqtt_port));
  Serial.println("\tapi_token : " + String(api_token));

  //save the custom parameters to FS
  if (shouldSaveConfig) {
    Serial.println("saving config");

    JsonDocument json;

    json["mqtt_server"] = mqtt_server;
    json["mqtt_port"] = mqtt_port;
    json["api_token"] = api_token;

    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");
    }

    serializeJson(json, Serial);
    serializeJson(json, configFile);

    configFile.close();
    //end save
  }

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

  //Start config portal manually (again) if there is some problem to access the device by wifi
  Serial.println("starting config portal (on demand/non blocking) for troubleshooting for 120s");
  wifiManager.setConfigPortalBlocking(false);
  wifiManager.setConfigPortalTimeout(120);
  wifiManager.startConfigPortal();

  Serial.println("starting web portal");
  wifiManager.startWebPortal();
  portalRunning = true;


}







//======= VOID LOOP ================================================================================


void loop() {
 
  // is auto timeout portal running
  if(portalRunning){
    wifiManager.process();
  }


}
Originally created by @exc2k on GitHub (Jan 30, 2024). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1706 Hello, once I configurated and connected to my WiFI my ESP crashes when I open the webportal or the configportal again (while connected to wifi) and clicking on "Configurate WiFi" or "Setup". "Info" works well. After it crashes it can't connect to my wifi anymore (authetication failure) and it goes into AP-Mode. Platform and Env: ``` platform = espressif32 board = lolin32 framework = arduino lib_deps = wnatth3/WiFiManager@^2.0.16-rc.2 bblanchon/ArduinoJson@^7.0.2 ``` Console Output: ``` mounting FS... mounted file system reading config file opened config file {"mqtt_server":"Mymqtt","mqtt_port":"8080","api_token":"YOUR_API_TOKEN","ip":"192.168.2.168","gateway":"192.168.2.1","subnet":"255.255.255.0"} parsed json setting custom ip from config 192.168.2.168 192.168.2.168 YOUR_API_TOKEN Mymqtt *wm:AutoConnect *wm:STA IP set: 192.168.2.168 *wm:Connecting to SAVED AP: Ikarus *wm:connectTimeout not set, ESP waitForConnectResult... *wm:AutoConnect: SUCCESS *wm:STA IP Address: 192.168.2.168 connected...yeey :) The values in the file are: mqtt_server : Mymqtt mqtt_port : 8080 api_token : YOUR_API_TOKEN local ip 192.168.2.168 192.168.2.1 255.255.255.0 starting config portal (on demand/non blocking) for troubleshooting for 120s *wm:StartAP with SSID: ESP32_6BCB94EC *wm:AP IP address: 192.168.4.1 *wm:Starting Web Portal starting web portal **HERE I CLICK ON CONFIG WIFI IN WEBPORTAL (OR CONFIGPORTAL)** *wm:11 networks found Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled. Core 1 register dump: PC : 0x40089e14 PS : 0x00060f30 A0 : 0x800e234d A1 : 0x3ffb1f30 A2 : 0x00000069 A3 : 0x00000065 A4 : 0x000000ff A5 : 0x0000ff00 A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x800e2188 A9 : 0x3ffb1f00 A10 : 0x3ffb1f6c A11 : 0x00000000 A12 : 0x00000014 A13 : 0x0000ff00 A14 : 0x00ff0000 A15 : 0xff000000 SAR : 0x00000018 EXCCAUSE: 0x0000001c EXCVADDR: 0x00000069 LBEG : 0x40089e35 LEND : 0x40089e45 LCOUNT : 0xfffffffa Backtrace: 0x40089e11:0x3ffb1f30 0x400e234a:0x3ffb1f40 0x400d8163:0x3ffb1f60 0x400d9dc9:0x3ffb1fa0 0x400decf2:0x3ffb2050 0x40166a59:0x3ffb20b0 0x400dbbbe:0x3ffb20d0 0x40155a5d:0x3ffb20f0 0x40155b3a:0x3ffb2130 0x40155cdd:0x3ffb21a0 0x400ddf36:0x3ffb21f0 0x400de13b:0x3ffb2250 0x400d3646:0x3ffb2270 0x400e3e75:0x3ffb2290 #0 0x40089e11:0x3ffb1f30 in strlen at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/machine/xtensa/strlen.S:43 #1 0x400e234a:0x3ffb1f40 in String::String(char const*) at C:/Users/dev/.platformio/packages/framework-arduinoespressif32/cores/esp32/WString.cpp:36 (inlined by) String::String(char const*) at C:/Users/dev/.platformio/packages/framework-arduinoespressif32/cores/esp32/WString.cpp:33 #2 0x400d8163:0x3ffb1f60 in String::replace(__FlashStringHelper const*, char const*) at C:/Users/dev/.platformio/packages/framework-arduinoespressif32/cores/esp32/WString.h:281 #3 0x400d9dc9:0x3ffb1fa0 in WiFiManager::getParamOut() at .pio/libdeps/lolin32/WiFiManager/WiFiManager.cpp:1776 (discriminator 1) #4 0x400decf2:0x3ffb2050 in WiFiManager::handleWifi(bool) at .pio/libdeps/lolin32/WiFiManager/WiFiManager.cpp:1392 #5 0x40166a59:0x3ffb20b0 in void std::__invoke_impl<void, void (WiFiManager::*&)(bool), WiFiManager*&, bool&>(std::__invoke_memfun_deref, void (WiFiManager::*&)(bool), WiFiManager*&, bool&) at c:\users\dev\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/invoke.h:73 (inlined by) std::__invoke_result<void (WiFiManager::*&)(bool), WiFiManager*&, bool&>::type std::__invoke<void (WiFiManager::*&)(bool), WiFiManager*&, bool&>(void (WiFiManager::*&)(bool), WiFiManager*&, bool&) at c:\users\dev\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/invoke.h:95 (inlined by) void std::_Bind<void (WiFiManager::*(WiFiManager*, bool))(bool)>::__call<void, , 0u, 1u>(std::tuple<>&&, std::_Index_tuple<0u, 1u>) at c:\users\dev\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0/functional:400 (inlined by) void std::_Bind<void (WiFiManager::*(WiFiManager*, bool))(bool)>::operator()<, void>() at c:\users\dev\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0/functional:484 (inlined by) std::_Function_handler<void (), std::_Bind<void (WiFiManager::*(WiFiManager*, bool))(bool)> >::_M_invoke(std::_Any_data const&) at c:\users\dev\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:297 #6 0x400dbbbe:0x3ffb20d0 in std::function<void ()>::operator()() const at c:\users\dev\.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\include\c++\8.4.0\bits/std_function.h:687 #7 0x40155a5d:0x3ffb20f0 in FunctionRequestHandler::handle(WebServer&, http_method, String) at C:/Users/dev/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/detail/RequestHandlersImpl.h:45 #8 0x40155b3a:0x3ffb2130 in WebServer::_handleRequest() at C:/Users/dev/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.cpp:651 #9 0x40155cdd:0x3ffb21a0 in WebServer::handleClient() at C:/Users/dev/.platformio/packages/framework-arduinoespressif32/libraries/WebServer/src/WebServer.cpp:318 #10 0x400ddf36:0x3ffb21f0 in WiFiManager::processConfigPortal() at .pio/libdeps/lolin32/WiFiManager/WiFiManager.cpp:871 #11 0x400de13b:0x3ffb2250 in WiFiManager::process() at .pio/libdeps/lolin32/WiFiManager/WiFiManager.cpp:851 #12 0x400d3646:0x3ffb2270 in loop() at src/main.cpp:241 #13 0x400e3e75:0x3ffb2290 in loopTask(void*) at C:/Users/dev/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:50 ``` I also get sometime a lot of this when I navigate through the portal: ``` [ 11228][E][WebServer.cpp:648] _handleRequest(): request handler not found ``` My code is basically copied from your examples with a few changes: ``` #include <Arduino.h> #include <FS.h> //this needs to be first, or it all crashes and burns... #include <WiFiManager.h> //https://github.com/tzapu/WiFiManager #ifdef ESP32 #include <SPIFFS.h> #endif #include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson //======= DEFINITIONS ================================================================================ const char AP_name[10] = "AP-Config"; //Access Point name const char AP_pw[16] = "12345678"; //Access Point password //define your default values here, if there are different values in config.json, they are overwritten. char mqtt_server[40]; char mqtt_port[6] = "8080"; char api_token[34] = "YOUR_API_TOKEN"; char static_ip[16] = "192.168.2.169"; char static_gw[16] = "192.168.2.1"; char static_sn[16] = "255.255.255.0"; //flag for saving data bool shouldSaveConfig = false; //New Config bool portalRunning = false; //Run Webportal //WiFiManager //Global init to have it in loop available WiFiManager wifiManager; //======= FUNCTIONS ================================================================================ //callback notifying us of the need to save config (remain for testing) void saveConfigCallback () { Serial.println("Should save config"); shouldSaveConfig = true; } //======= VOID SETUP ================================================================================ void setup() { // put your setup code here, to run once: Serial.begin(115200); Serial.println(); //clean FS, for testing //SPIFFS.format(); //read configuration from FS json Serial.println("mounting FS..."); if (!SPIFFS.begin()) { Serial.println("mounting filesystem failed.. trying to format"); SPIFFS.format(); Serial.println("trying again to mount 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); JsonDocument json; auto deserializeError = deserializeJson(json, buf.get()); serializeJson(json, Serial); if (!deserializeError ) { Serial.println("\nparsed json"); strcpy(mqtt_server, json["mqtt_server"]); strcpy(mqtt_port, json["mqtt_port"]); strcpy(api_token, json["api_token"]); 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"); } configFile.close(); } } } else { Serial.println("failed to mount FS"); } //end read Serial.println(static_ip); Serial.println(api_token); Serial.println(mqtt_server); // 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_mqtt_server("server", "mqtt server", mqtt_server, 40); WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 6); WiFiManagerParameter custom_api_token("apikey", "API token", api_token, 32); //set config save notify callback wifiManager.setSaveConfigCallback(saveConfigCallback); wifiManager.setBreakAfterConfig(true); //set static ip IPAddress _ip, _gw, _sn; _ip.fromString(static_ip); _gw.fromString(static_gw); _sn.fromString(static_sn); wifiManager.setSTAStaticIPConfig(_ip, _gw, _sn); //add all your parameters here wifiManager.addParameter(&custom_mqtt_server); wifiManager.addParameter(&custom_mqtt_port); wifiManager.addParameter(&custom_api_token); //reset settings - for testing //wifiManager.resetSettings(); //set minimu quality of signal so it ignores AP's under that quality //defaults to 8% //wifiManager.setMinimumSignalQuality(); //sets timeout until configuration portal gets turned off //useful to make it all retry or go to sleep //in seconds wifiManager.setTimeout(300); //fetches ssid and pass and tries to connect //if it does not connect it starts an access point with the specified name //and goes into a blocking loop awaiting configuration if (!wifiManager.autoConnect(AP_name, AP_pw)) { Serial.println("failed to connect and hit timeout"); delay(3000); //reset and try again, or maybe put it to deep sleep ESP.restart(); delay(5000); } //if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); //read updated parameters strcpy(mqtt_server, custom_mqtt_server.getValue()); strcpy(mqtt_port, custom_mqtt_port.getValue()); strcpy(api_token, custom_api_token.getValue()); Serial.println("The values in the file are: "); Serial.println("\tmqtt_server : " + String(mqtt_server)); Serial.println("\tmqtt_port : " + String(mqtt_port)); Serial.println("\tapi_token : " + String(api_token)); //save the custom parameters to FS if (shouldSaveConfig) { Serial.println("saving config"); JsonDocument json; json["mqtt_server"] = mqtt_server; json["mqtt_port"] = mqtt_port; json["api_token"] = api_token; 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"); } serializeJson(json, Serial); serializeJson(json, configFile); configFile.close(); //end save } Serial.println("local ip"); Serial.println(WiFi.localIP()); Serial.println(WiFi.gatewayIP()); Serial.println(WiFi.subnetMask()); //Start config portal manually (again) if there is some problem to access the device by wifi Serial.println("starting config portal (on demand/non blocking) for troubleshooting for 120s"); wifiManager.setConfigPortalBlocking(false); wifiManager.setConfigPortalTimeout(120); wifiManager.startConfigPortal(); Serial.println("starting web portal"); wifiManager.startWebPortal(); portalRunning = true; } //======= VOID LOOP ================================================================================ void loop() { // is auto timeout portal running if(portalRunning){ wifiManager.process(); } } ```
kerem closed this issue 2026-02-28 01:30:06 +03:00
Author
Owner

@tablatronix commented on GitHub (Jan 30, 2024):

You are using git version?
What esp sdk ver?

<!-- gh-comment-id:1918048139 --> @tablatronix commented on GitHub (Jan 30, 2024): You are using git version? What esp sdk ver?
Author
Owner

@exc2k commented on GitHub (Jan 31, 2024):

I changed the board today and now it is working. Absolutly no idea what was wrong with the hardware. Very strange behaviour. Sorry for bothering you.

<!-- gh-comment-id:1919303582 --> @exc2k commented on GitHub (Jan 31, 2024): I changed the board today and now it is working. Absolutly no idea what was wrong with the hardware. Very strange behaviour. Sorry for bothering you.
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#1444
No description provided.