[GH-ISSUE #1580] IP,GetWay and SubNetMask set to :0.0.0.0 #1349

Closed
opened 2026-02-28 01:29:42 +03:00 by kerem · 16 comments
Owner

Originally created by @Mehdi-Dehghan on GitHub (Apr 2, 2023).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1580

PLEASE TRY Latest Master BRANCH before submitting bugs, in case they were already fixed.

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

Esp8266/Esp32: ESP32

Hardware: ESP32 240MHz, 520KB RAM, 4MB Flash

Core Version: 2.0.15-rc.1

Description

Problem description

Settings in IDE

Module: ESP32-DevKitC

Additional libraries:

Sketch

#BEGIN
#include <Arduino.h>

void setup() {
  wifiManager.setAPCallback(configModeCallback);
  wifiManager.setWebServerCallback(bindServerCallback);
  wifiManager.setSaveConfigCallback(saveWifiCallback);
  wifiManager.setSaveParamsCallback(saveParamCallback);
  wifiManager.setShowStaticFields(true); // force show static ip fields

  //start-block1
  IPAddress _ip,_gw,_sn;
  _ip.fromString(static_ip);
  _gw.fromString(static_gw);
  _sn.fromString(static_sn);
  //end-block1
  wifiManager.setSTAStaticIPConfig(_ip,_gw,_sn);
  wifiManager.setConfigPortalTimeout(60);
  
  wifiManager.autoConnect("MyTest");
  
  Serial.println("---------First Step---------");
  Serial.println(WiFi.localIP());
  Serial.println(WiFi.gatewayIP());
  Serial.println(WiFi.subnetMask());
}

void loop() {

}
#END

Debug Messages

STA IP set:0.0.0.0
STA GetWay set:0.0.0.0
STA SubNetMask set:0.0.0.0
messages here
Hi

I tried to set IP, GetWay, subnetmask and also SSID, Password in portal. but All IP's set to 0.0.0.0
How can I cope this issue?

Thanks in advance

Originally created by @Mehdi-Dehghan on GitHub (Apr 2, 2023). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1580 ## PLEASE TRY Latest Master BRANCH before submitting bugs, in case they were already fixed. ## 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 Esp8266/Esp32: ESP32 Hardware: ESP32 240MHz, 520KB RAM, 4MB Flash Core Version: 2.0.15-rc.1 ### Description Problem description ### Settings in IDE Module: ESP32-DevKitC Additional libraries: ### Sketch ```cpp #BEGIN #include <Arduino.h> void setup() { wifiManager.setAPCallback(configModeCallback); wifiManager.setWebServerCallback(bindServerCallback); wifiManager.setSaveConfigCallback(saveWifiCallback); wifiManager.setSaveParamsCallback(saveParamCallback); wifiManager.setShowStaticFields(true); // force show static ip fields //start-block1 IPAddress _ip,_gw,_sn; _ip.fromString(static_ip); _gw.fromString(static_gw); _sn.fromString(static_sn); //end-block1 wifiManager.setSTAStaticIPConfig(_ip,_gw,_sn); wifiManager.setConfigPortalTimeout(60); wifiManager.autoConnect("MyTest"); Serial.println("---------First Step---------"); Serial.println(WiFi.localIP()); Serial.println(WiFi.gatewayIP()); Serial.println(WiFi.subnetMask()); } void loop() { } #END ``` ### Debug Messages STA IP set:0.0.0.0 STA GetWay set:0.0.0.0 STA SubNetMask set:0.0.0.0 messages here Hi I tried to set IP, GetWay, subnetmask and also SSID, Password in portal. but All IP's set to 0.0.0.0 How can I cope this issue? Thanks in advance
kerem 2026-02-28 01:29:42 +03:00
  • closed this issue
  • added the
    Question
    label
Author
Owner

@tablatronix commented on GitHub (Apr 2, 2023):

Show me your variables for ips

<!-- gh-comment-id:1493462754 --> @tablatronix commented on GitHub (Apr 2, 2023): Show me your variables for ips
Author
Owner

@Mehdi-Dehghan commented on GitHub (Apr 3, 2023):

Thanks for your reply.
this is my complete code:

//#include <ESP8266WiFi.h>
#include <WiFi.h>
#include <WiFiClient.h>
//#include <ESP8266WebServer.h>
#include <WebServer.h>
#include <SPIFFS.h>
#include <FS.h> // FOR LittleFS
#include <ctype.h> // for isNumber check
#include <WiFiManager.h> 

//---------------------------
//default custom static IP
char static_ip[16];// = "192.168.1.56";
char static_gw[16];// = "192.168.1.1";
char static_sn[16];// = "255.255.255.0";
//---------------------------------------------------------------
WebServer server(80);
WiFiManager wifiManager;
//---------------------------------------------------------------
//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;
  Serial.println(WiFi.localIP().toString());
  Serial.println(WiFi.gatewayIP().toString());
  Serial.println(WiFi.subnetMask().toString());
}

void saveWifiCallback()
{
  Serial.println("[CALLBACK] saveCallback fired");
}

//gets called when WiFiManager enters configuration mode
void configModeCallback (WiFiManager *myWiFiManager) 
{
  Serial.println("[CALLBACK] configModeCallback fired");
  // myWiFiManager->setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); 
  // Serial.println(WiFi.softAPIP());
  //if you used auto generated SSID, print it
  // Serial.println(myWiFiManager->getConfigPortalSSID());
  // 
  // esp_wifi_set_bandwidth(WIFI_IF_AP, WIFI_BW_HT20);
}

void saveParamCallback()
{
  shouldSaveConfig = true;
  Serial.println("========================================");
  Serial.println("[CALLBACK] saveParamCallback fired");
  Serial.print("STA IP set:");
  Serial.println(WiFi.localIP());
  Serial.print("STA GetWay set:");
  Serial.println(WiFi.gatewayIP());
  Serial.print("STA SubNetMask set:");
  Serial.println(WiFi.subnetMask());
  wifiManager.setSTAStaticIPConfig(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask());
  //save the custom parameters to FS
 
  Serial.println("========================================");
  // wm.stopConfigPortal();
}

void bindServerCallback()
{
  //wifiManager.server->on("/custom",handleRoute); // this is now crashing esp32 for some reason
  // wm.server->on("/info",handleRoute); // you can override wm!
}
//---------------------------------------------------------------
//---------------------------------------------------------------
///////////////////////////////////////
// first funtion to run at power up //
//////////////////////////////////////

void setup(void)
{
  // You can open the Arduino IDE Serial Monitor window to see what the code is doing
  Serial.begin(115200);

  wifiManager.setClass("invert"); // dark theme
  wifiManager.setDebugOutput(true);
  wifiManager.setAPCallback(configModeCallback);
  wifiManager.setWebServerCallback(bindServerCallback);
  wifiManager.setSaveConfigCallback(saveWifiCallback);
  wifiManager.setSaveParamsCallback(saveParamCallback);
  wifiManager.setShowStaticFields(true); // force show static ip fields

  IPAddress _ip,_gw,_sn;
  _ip.fromString(static_ip);
  _gw.fromString(static_gw);
  _sn.fromString(static_sn);
  
  wifiManager.setSTAStaticIPConfig(_ip,_gw,_sn);
  wifiManager.setConfigPortalTimeout(60);
  // wifiManager.startConfigPortal("OnDemandAP");
  wifiManager.autoConnect("MyTest");
  // wifiManager.persistent(true);
  
 if (shouldSaveConfig) 
  {
    shouldSaveConfig = false;
    Serial.println("saving config");
    Serial.println(WiFi.localIP());
    Serial.println(WiFi.gatewayIP());
    Serial.println(WiFi.subnetMask());
    //end save
  }
  
  if (WiFi.status() == WL_CONNECTED)
  {
    Serial.print("\n\r \n\rWorking to connect");
    Serial.print("Connected to ");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    Serial.println(WiFi.gatewayIP());
    Serial.println(WiFi.subnetMask());
  }
  delay(10);

}

////////////////////////////////////////////////////////////////////////////////

void loop(void)
{



}
<!-- gh-comment-id:1494263311 --> @Mehdi-Dehghan commented on GitHub (Apr 3, 2023): Thanks for your reply. this is my complete code: ```cpp //#include <ESP8266WiFi.h> #include <WiFi.h> #include <WiFiClient.h> //#include <ESP8266WebServer.h> #include <WebServer.h> #include <SPIFFS.h> #include <FS.h> // FOR LittleFS #include <ctype.h> // for isNumber check #include <WiFiManager.h> //--------------------------- //default custom static IP char static_ip[16];// = "192.168.1.56"; char static_gw[16];// = "192.168.1.1"; char static_sn[16];// = "255.255.255.0"; //--------------------------------------------------------------- WebServer server(80); WiFiManager wifiManager; //--------------------------------------------------------------- //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; Serial.println(WiFi.localIP().toString()); Serial.println(WiFi.gatewayIP().toString()); Serial.println(WiFi.subnetMask().toString()); } void saveWifiCallback() { Serial.println("[CALLBACK] saveCallback fired"); } //gets called when WiFiManager enters configuration mode void configModeCallback (WiFiManager *myWiFiManager) { Serial.println("[CALLBACK] configModeCallback fired"); // myWiFiManager->setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); // Serial.println(WiFi.softAPIP()); //if you used auto generated SSID, print it // Serial.println(myWiFiManager->getConfigPortalSSID()); // // esp_wifi_set_bandwidth(WIFI_IF_AP, WIFI_BW_HT20); } void saveParamCallback() { shouldSaveConfig = true; Serial.println("========================================"); Serial.println("[CALLBACK] saveParamCallback fired"); Serial.print("STA IP set:"); Serial.println(WiFi.localIP()); Serial.print("STA GetWay set:"); Serial.println(WiFi.gatewayIP()); Serial.print("STA SubNetMask set:"); Serial.println(WiFi.subnetMask()); wifiManager.setSTAStaticIPConfig(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask()); //save the custom parameters to FS Serial.println("========================================"); // wm.stopConfigPortal(); } void bindServerCallback() { //wifiManager.server->on("/custom",handleRoute); // this is now crashing esp32 for some reason // wm.server->on("/info",handleRoute); // you can override wm! } //--------------------------------------------------------------- //--------------------------------------------------------------- /////////////////////////////////////// // first funtion to run at power up // ////////////////////////////////////// void setup(void) { // You can open the Arduino IDE Serial Monitor window to see what the code is doing Serial.begin(115200); wifiManager.setClass("invert"); // dark theme wifiManager.setDebugOutput(true); wifiManager.setAPCallback(configModeCallback); wifiManager.setWebServerCallback(bindServerCallback); wifiManager.setSaveConfigCallback(saveWifiCallback); wifiManager.setSaveParamsCallback(saveParamCallback); wifiManager.setShowStaticFields(true); // force show static ip fields IPAddress _ip,_gw,_sn; _ip.fromString(static_ip); _gw.fromString(static_gw); _sn.fromString(static_sn); wifiManager.setSTAStaticIPConfig(_ip,_gw,_sn); wifiManager.setConfigPortalTimeout(60); // wifiManager.startConfigPortal("OnDemandAP"); wifiManager.autoConnect("MyTest"); // wifiManager.persistent(true); if (shouldSaveConfig) { shouldSaveConfig = false; Serial.println("saving config"); Serial.println(WiFi.localIP()); Serial.println(WiFi.gatewayIP()); Serial.println(WiFi.subnetMask()); //end save } if (WiFi.status() == WL_CONNECTED) { Serial.print("\n\r \n\rWorking to connect"); Serial.print("Connected to "); Serial.println("IP address: "); Serial.println(WiFi.localIP()); Serial.println(WiFi.gatewayIP()); Serial.println(WiFi.subnetMask()); } delay(10); } //////////////////////////////////////////////////////////////////////////////// void loop(void) { } ```
Author
Owner

@tablatronix commented on GitHub (Apr 3, 2023):

And if you uncomment these? what happens?
you know you have to save these somewhere right? ESP does not

char static_ip[16];// = "192.168.1.56";
char static_gw[16];// = "192.168.1.1";
char static_sn[16];// = "255.255.255.0";
<!-- gh-comment-id:1494859780 --> @tablatronix commented on GitHub (Apr 3, 2023): And if you uncomment these? what happens? you know you have to save these somewhere right? ESP does not ``` char static_ip[16];// = "192.168.1.56"; char static_gw[16];// = "192.168.1.1"; char static_sn[16];// = "255.255.255.0"; ```
Author
Owner

@Mehdi-Dehghan commented on GitHub (Apr 3, 2023):

And if you uncomment these? what happens? you know you have to save these somewhere right? ESP does not

char static_ip[16];// = "192.168.1.56";
char static_gw[16];// = "192.168.1.1";
char static_sn[16];// = "255.255.255.0";

I uncommented and in portal showed those IPs. but when I changed in portal (192.168.4.1 adress) to another things they were still fixed:

load:0x3fff0030,len:1184
load:0x40078000,len:13192
load:0x40080400,len:3028
entry 0x400805e4
*wm:AutoConnect 
*wm:STA IP set: 192.168.1.56
*wm:Connecting to SAVED AP: New
*wm:connectTimeout not set, ESP waitForConnectResult... 
*wm:AutoConnect: FAILED for  3127 ms
*wm:StartAP with SSID:  MyTest
*wm:AP IP address: 192.168.4.1
[CALLBACK] configModeCallback fired
*wm:Starting Web Portal
*wm:1 networks found
[ 64610][E][WebServer.cpp:649] _handleRequest(): request handler not found
[ 64636][E][WebServer.cpp:649] _handleRequest(): request handler not found
========================================
[CALLBACK] saveParamCallback fired
STA IP set:192.168.1.56
STA GetWay set:192.168.1.1
STA SubNetMask set:255.255.255.0
========================================
*wm:STA IP set: 192.168.1.56
*wm:Connecting to NEW AP: New
*wm:connectTimeout not set, ESP waitForConnectResult... 
*wm:[ERROR] Connect to new AP Failed 
*wm:config portal has timed out 
*wm:config portal exiting 
saving config
192.168.1.56
192.168.1.1
255.255.255.0
<!-- gh-comment-id:1494978567 --> @Mehdi-Dehghan commented on GitHub (Apr 3, 2023): > And if you uncomment these? what happens? you know you have to save these somewhere right? ESP does not > > ``` > char static_ip[16];// = "192.168.1.56"; > char static_gw[16];// = "192.168.1.1"; > char static_sn[16];// = "255.255.255.0"; > ``` I uncommented and in portal showed those IPs. but when I changed in portal (192.168.4.1 adress) to another things they were still fixed: ``` load:0x3fff0030,len:1184 load:0x40078000,len:13192 load:0x40080400,len:3028 entry 0x400805e4 *wm:AutoConnect *wm:STA IP set: 192.168.1.56 *wm:Connecting to SAVED AP: New *wm:connectTimeout not set, ESP waitForConnectResult... *wm:AutoConnect: FAILED for 3127 ms *wm:StartAP with SSID: MyTest *wm:AP IP address: 192.168.4.1 [CALLBACK] configModeCallback fired *wm:Starting Web Portal *wm:1 networks found [ 64610][E][WebServer.cpp:649] _handleRequest(): request handler not found [ 64636][E][WebServer.cpp:649] _handleRequest(): request handler not found ======================================== [CALLBACK] saveParamCallback fired STA IP set:192.168.1.56 STA GetWay set:192.168.1.1 STA SubNetMask set:255.255.255.0 ======================================== *wm:STA IP set: 192.168.1.56 *wm:Connecting to NEW AP: New *wm:connectTimeout not set, ESP waitForConnectResult... *wm:[ERROR] Connect to new AP Failed *wm:config portal has timed out *wm:config portal exiting saving config 192.168.1.56 192.168.1.1 255.255.255.0 ```
Author
Owner

@tablatronix commented on GitHub (Apr 4, 2023):

hmm, I think you will need to reconnect to apply the new ip. But they will be gone again if you reboot, you will have to save them in flash(littelfs) and load on boot

<!-- gh-comment-id:1495155095 --> @tablatronix commented on GitHub (Apr 4, 2023): hmm, I think you will need to reconnect to apply the new ip. But they will be gone again if you reboot, you will have to save them in flash(littelfs) and load on boot
Author
Owner

@Mehdi-Dehghan commented on GitHub (Apr 4, 2023):

I did several times (reconnect & save in flash). but that still has this issue.
I tried to change IPs!

//#include <ESP8266WiFi.h>
#include <WiFi.h>
#include <WiFiClient.h>
//#include <ESP8266WebServer.h>
#include <WebServer.h>
#include <SPIFFS.h>
#include <FS.h> // FOR LittleFS
#include <ctype.h> // for isNumber check
#include <WiFiManager.h> 
#include <ArduinoJson.h>
//---------------------------
//default custom static IP
char static_ip[16] = "192.168.1.7";
char static_gw[16] = "192.168.1.1";
char static_sn[16] = "255.255.255.0";
//---------------------------------------------------------------
WebServer server(80);
WiFiManager wifiManager;
//---------------------------------------------------------------
//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;
  Serial.println(WiFi.localIP().toString());
  Serial.println(WiFi.gatewayIP().toString());
  Serial.println(WiFi.subnetMask().toString());
}

void saveWifiCallback()
{
  Serial.println("[CALLBACK] saveCallback fired");
}

//gets called when WiFiManager enters configuration mode
void configModeCallback (WiFiManager *myWiFiManager) 
{
  Serial.println("[CALLBACK] configModeCallback fired");
  // myWiFiManager->setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); 
  // Serial.println(WiFi.softAPIP());
  //if you used auto generated SSID, print it
  // Serial.println(myWiFiManager->getConfigPortalSSID());
  // 
  // esp_wifi_set_bandwidth(WIFI_IF_AP, WIFI_BW_HT20);
}

void saveParamCallback()
{
  shouldSaveConfig = true;
  Serial.println("========================================");
  Serial.println("[CALLBACK] saveParamCallback fired");
  Serial.print("STA IP set:");
  Serial.println(WiFi.localIP());
  Serial.print("STA GetWay set:");
  Serial.println(WiFi.gatewayIP());
  Serial.print("STA SubNetMask set:");
  Serial.println(WiFi.subnetMask());
  wifiManager.setSTAStaticIPConfig(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask());
  //save the custom parameters to FS
 
  Serial.println("========================================");
  // wm.stopConfigPortal();
}

void bindServerCallback()
{
  //wifiManager.server->on("/custom",handleRoute); // this is now crashing esp32 for some reason
  // wm.server->on("/info",handleRoute); // you can override wm!
}
//---------------------------------------------------------------
//---------------------------------------------------------------
///////////////////////////////////////
// first funtion to run at power up //
//////////////////////////////////////

void setup(void)
{
  // You can open the Arduino IDE Serial Monitor window to see what the code is doing
  Serial.begin(115200);

  wifiManager.setClass("invert"); // dark theme
  wifiManager.setDebugOutput(true);
  wifiManager.setAPCallback(configModeCallback);
  wifiManager.setWebServerCallback(bindServerCallback);
  wifiManager.setSaveConfigCallback(saveWifiCallback);
  wifiManager.setSaveParamsCallback(saveParamCallback);
  wifiManager.setShowStaticFields(true); // force show static ip fields

  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);
        DynamicJsonDocument json(1024);
        auto deserializeError = deserializeJson(json, buf.get());
        serializeJson(json, Serial);
        if ( ! deserializeError ) 
        {
          Serial.println("\nparsed json");
          strcpy(static_ip, json["static_ip"]);
          strcpy(static_gw, json["static_gw"]);
          strcpy(static_sn, json["static_sn"]);
        } 
        else 
        {
          Serial.println("failed to load json config");
        }
        configFile.close();
      }
    }
  } 
  else 
  {
    Serial.println("failed to mount FS");
  }
 
  IPAddress _ip,_gw,_sn;
  _ip.fromString(static_ip);
  _gw.fromString(static_gw);
  _sn.fromString(static_sn);
  
  wifiManager.setSTAStaticIPConfig(_ip,_gw,_sn);
  wifiManager.setConfigPortalTimeout(60);
  
  wifiManager.autoConnect("MyTest");
  
  Serial.println(WiFi.localIP());
  Serial.println(WiFi.gatewayIP());
  Serial.println(WiFi.subnetMask());
  if (shouldSaveConfig) 
  {
    shouldSaveConfig = false;
    Serial.println("saving config");
    DynamicJsonDocument json(1024);

    json["static_ip"] = WiFi.localIP();//static_ip;
    json["static_gw"] = WiFi.gatewayIP();//static_gw;
    json["static_sn"] = WiFi.subnetMask();//static_sn;

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

  if (WiFi.status() == WL_CONNECTED)
  {
    Serial.print("\n\r \n\rWorking to connect");
    Serial.print("Connected to ");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
  }
  delay(10);

}

////////////////////////////////////////////////////////////////////////////////

void loop(void)
{



}

OutPut:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13192
load:0x40080400,len:3028
entry 0x400805e4
mounting FS...
mounted file system
reading config file
opened config file
{"static_ip":"192.168.1.7","static_gw":"192.168.1.1","static_sn":"255.255.255.0"}
parsed json
*wm:AutoConnect
*wm:STA IP set: 192.168.1.7
*wm:Connecting to SAVED AP: New
*wm:connectTimeout not set, ESP waitForConnectResult... 
*wm:AutoConnect: FAILED for  60628 ms
*wm:StartAP with SSID:  MyTest
*wm:AP IP address: 192.168.4.1
[CALLBACK] configModeCallback fired
*wm:Starting Web Portal
*wm:1 networks found
========================================
[CALLBACK] saveParamCallback fired
STA IP set:192.168.1.7
STA GetWay set:192.168.1.1
STA SubNetMask set:255.255.255.0
========================================
*wm:STA IP set: 192.168.1.7
*wm:Connecting to NEW AP: New
*wm:connectTimeout not set, ESP waitForConnectResult...
*wm:[ERROR] Connect to new AP Failed 
*wm:config portal has timed out
*wm:config portal exiting 
192.168.1.7
192.168.1.1
255.255.255.0
saving config
{"static_ip":"192.168.1.7","static_gw":"192.168.1.1","static_sn":"255.255.255.0"}
<!-- gh-comment-id:1495483720 --> @Mehdi-Dehghan commented on GitHub (Apr 4, 2023): I did several times (reconnect & save in flash). but that still has this issue. I tried to change IPs! ```C++ //#include <ESP8266WiFi.h> #include <WiFi.h> #include <WiFiClient.h> //#include <ESP8266WebServer.h> #include <WebServer.h> #include <SPIFFS.h> #include <FS.h> // FOR LittleFS #include <ctype.h> // for isNumber check #include <WiFiManager.h> #include <ArduinoJson.h> //--------------------------- //default custom static IP char static_ip[16] = "192.168.1.7"; char static_gw[16] = "192.168.1.1"; char static_sn[16] = "255.255.255.0"; //--------------------------------------------------------------- WebServer server(80); WiFiManager wifiManager; //--------------------------------------------------------------- //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; Serial.println(WiFi.localIP().toString()); Serial.println(WiFi.gatewayIP().toString()); Serial.println(WiFi.subnetMask().toString()); } void saveWifiCallback() { Serial.println("[CALLBACK] saveCallback fired"); } //gets called when WiFiManager enters configuration mode void configModeCallback (WiFiManager *myWiFiManager) { Serial.println("[CALLBACK] configModeCallback fired"); // myWiFiManager->setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); // Serial.println(WiFi.softAPIP()); //if you used auto generated SSID, print it // Serial.println(myWiFiManager->getConfigPortalSSID()); // // esp_wifi_set_bandwidth(WIFI_IF_AP, WIFI_BW_HT20); } void saveParamCallback() { shouldSaveConfig = true; Serial.println("========================================"); Serial.println("[CALLBACK] saveParamCallback fired"); Serial.print("STA IP set:"); Serial.println(WiFi.localIP()); Serial.print("STA GetWay set:"); Serial.println(WiFi.gatewayIP()); Serial.print("STA SubNetMask set:"); Serial.println(WiFi.subnetMask()); wifiManager.setSTAStaticIPConfig(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask()); //save the custom parameters to FS Serial.println("========================================"); // wm.stopConfigPortal(); } void bindServerCallback() { //wifiManager.server->on("/custom",handleRoute); // this is now crashing esp32 for some reason // wm.server->on("/info",handleRoute); // you can override wm! } //--------------------------------------------------------------- //--------------------------------------------------------------- /////////////////////////////////////// // first funtion to run at power up // ////////////////////////////////////// void setup(void) { // You can open the Arduino IDE Serial Monitor window to see what the code is doing Serial.begin(115200); wifiManager.setClass("invert"); // dark theme wifiManager.setDebugOutput(true); wifiManager.setAPCallback(configModeCallback); wifiManager.setWebServerCallback(bindServerCallback); wifiManager.setSaveConfigCallback(saveWifiCallback); wifiManager.setSaveParamsCallback(saveParamCallback); wifiManager.setShowStaticFields(true); // force show static ip fields 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); DynamicJsonDocument json(1024); auto deserializeError = deserializeJson(json, buf.get()); serializeJson(json, Serial); if ( ! deserializeError ) { Serial.println("\nparsed json"); strcpy(static_ip, json["static_ip"]); strcpy(static_gw, json["static_gw"]); strcpy(static_sn, json["static_sn"]); } else { Serial.println("failed to load json config"); } configFile.close(); } } } else { Serial.println("failed to mount FS"); } IPAddress _ip,_gw,_sn; _ip.fromString(static_ip); _gw.fromString(static_gw); _sn.fromString(static_sn); wifiManager.setSTAStaticIPConfig(_ip,_gw,_sn); wifiManager.setConfigPortalTimeout(60); wifiManager.autoConnect("MyTest"); Serial.println(WiFi.localIP()); Serial.println(WiFi.gatewayIP()); Serial.println(WiFi.subnetMask()); if (shouldSaveConfig) { shouldSaveConfig = false; Serial.println("saving config"); DynamicJsonDocument json(1024); json["static_ip"] = WiFi.localIP();//static_ip; json["static_gw"] = WiFi.gatewayIP();//static_gw; json["static_sn"] = WiFi.subnetMask();//static_sn; 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(); } if (WiFi.status() == WL_CONNECTED) { Serial.print("\n\r \n\rWorking to connect"); Serial.print("Connected to "); Serial.println("IP address: "); Serial.println(WiFi.localIP()); } delay(10); } //////////////////////////////////////////////////////////////////////////////// void loop(void) { } ``` OutPut: ``` rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:2 load:0x3fff0030,len:1184 load:0x40078000,len:13192 load:0x40080400,len:3028 entry 0x400805e4 mounting FS... mounted file system reading config file opened config file {"static_ip":"192.168.1.7","static_gw":"192.168.1.1","static_sn":"255.255.255.0"} parsed json *wm:AutoConnect *wm:STA IP set: 192.168.1.7 *wm:Connecting to SAVED AP: New *wm:connectTimeout not set, ESP waitForConnectResult... *wm:AutoConnect: FAILED for 60628 ms *wm:StartAP with SSID: MyTest *wm:AP IP address: 192.168.4.1 [CALLBACK] configModeCallback fired *wm:Starting Web Portal *wm:1 networks found ======================================== [CALLBACK] saveParamCallback fired STA IP set:192.168.1.7 STA GetWay set:192.168.1.1 STA SubNetMask set:255.255.255.0 ======================================== *wm:STA IP set: 192.168.1.7 *wm:Connecting to NEW AP: New *wm:connectTimeout not set, ESP waitForConnectResult... *wm:[ERROR] Connect to new AP Failed *wm:config portal has timed out *wm:config portal exiting 192.168.1.7 192.168.1.1 255.255.255.0 saving config {"static_ip":"192.168.1.7","static_gw":"192.168.1.1","static_sn":"255.255.255.0"} ```
Author
Owner

@Mehdi-Dehghan commented on GitHub (Apr 4, 2023):

I like to say, befor using ESP32, I used ESP8266 and it hadn't any problem and worked well!

<!-- gh-comment-id:1495488268 --> @Mehdi-Dehghan commented on GitHub (Apr 4, 2023): I like to say, befor using ESP32, I used ESP8266 and it hadn't any problem and worked well!
Author
Owner

@tablatronix commented on GitHub (Apr 4, 2023):

Ok let me look at that full code thanks

<!-- gh-comment-id:1495853960 --> @tablatronix commented on GitHub (Apr 4, 2023): Ok let me look at that full code thanks
Author
Owner

@tablatronix commented on GitHub (Apr 4, 2023):

Ok why is your connection failing though? Looks like wrong password

<!-- gh-comment-id:1496683832 --> @tablatronix commented on GitHub (Apr 4, 2023): Ok why is your connection failing though? Looks like wrong password
Author
Owner

@tablatronix commented on GitHub (Apr 4, 2023):

There is something else going on here,

[ 38365][V][WebServer.cpp:296] handleClient(): New client: client.localIP()=0.0.0.0

Let me figure out wtf is going on, looks like an esp bug

<!-- gh-comment-id:1496706402 --> @tablatronix commented on GitHub (Apr 4, 2023): There is something else going on here, `[ 38365][V][WebServer.cpp:296] handleClient(): New client: client.localIP()=0.0.0.0` Let me figure out wtf is going on, looks like an esp bug
Author
Owner

@tablatronix commented on GitHub (Apr 4, 2023):

oh I was stuck on tasmotas esp32 , had to force remove my platofrm in pio

<!-- gh-comment-id:1496737103 --> @tablatronix commented on GitHub (Apr 4, 2023): oh I was stuck on tasmotas esp32 , had to force remove my platofrm in pio
Author
Owner

@tablatronix commented on GitHub (Apr 5, 2023):

ugh

mounting FS...
E (675) SPIFFS: mount failed, -10025
[   685][E][SPIFFS.cpp:89] begin(): Mounting SPIFFS failed! Error: -1
[     7][D][esp32-hal-cpu.c:244] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
./components/esp_littlefs/src/littlefs/lfs.c:1229:error: Corrupted dir pair at {0x0, 0x1}
E (34) esp_littlefs: mount failed,  (-84)
E (35) esp_littlefs: Failed to initialize LittleFS
[    44][E][LittleFS.cpp:95] begin(): Mounting LittleFS failed! Error: -1

My pio enviroment is not initializing partitions properly, no idea why

EDIT: I added a format in code, I thought esptool handled this

<!-- gh-comment-id:1496761252 --> @tablatronix commented on GitHub (Apr 5, 2023): ugh ``` mounting FS... E (675) SPIFFS: mount failed, -10025 [ 685][E][SPIFFS.cpp:89] begin(): Mounting SPIFFS failed! Error: -1 ``` ``` [ 7][D][esp32-hal-cpu.c:244] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz ./components/esp_littlefs/src/littlefs/lfs.c:1229:error: Corrupted dir pair at {0x0, 0x1} E (34) esp_littlefs: mount failed, (-84) E (35) esp_littlefs: Failed to initialize LittleFS [ 44][E][LittleFS.cpp:95] begin(): Mounting LittleFS failed! Error: -1 ``` My pio enviroment is not initializing partitions properly, no idea why EDIT: I added a format in code, I thought esptool handled this
Author
Owner

@tablatronix commented on GitHub (Apr 5, 2023):

This is wrong.

saveParamCallback

  wifiManager.setSTAStaticIPConfig(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask());

you should be passing in the parameters here, but wm does this on save automatically for staticip params, so just delete this line or the entire callback

<!-- gh-comment-id:1496777073 --> @tablatronix commented on GitHub (Apr 5, 2023): This is wrong. saveParamCallback ``` wifiManager.setSTAStaticIPConfig(WiFi.localIP(), WiFi.gatewayIP(), WiFi.subnetMask()); ``` you should be passing in the parameters here, but wm does this on save automatically for staticip params, so just delete this line or the entire callback
Author
Owner

@Mehdi-Dehghan commented on GitHub (Apr 5, 2023):

Thanks for your time.

<!-- gh-comment-id:1497013540 --> @Mehdi-Dehghan commented on GitHub (Apr 5, 2023): Thanks for your time.
Author
Owner

@tablatronix commented on GitHub (Apr 5, 2023):

Get it working?

<!-- gh-comment-id:1498282894 --> @tablatronix commented on GitHub (Apr 5, 2023): Get it working?
Author
Owner

@Mehdi-Dehghan commented on GitHub (Apr 16, 2023):

Yes That works true.
Thanks a lot

<!-- gh-comment-id:1510269359 --> @Mehdi-Dehghan commented on GitHub (Apr 16, 2023): Yes That works true. Thanks a lot
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#1349
No description provided.