[GH-ISSUE #1308] how i can save the Static IP information that as been inserted from the portal ? #1121

Open
opened 2026-02-28 01:28:37 +03:00 by kerem · 2 comments
Owner

Originally created by @learn05 on GitHub (Nov 8, 2021).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1308

#include <WiFiManager.h>

// Define the Wifi Manager Params
WiFiManager wm;
void saveParamCallback(){
Serial.println("[CALLBACK] saveParamCallback fired");
// wm.stopConfigPortal();
}
void saveWifiCallback(){
Serial.println("[CALLBACK] saveCallback fired");
}
//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 setup()
{
WiFi.mode(WIFI_STA);
Serial.begin(115200);
wm.debugPlatformInfo();
wm.setCountry("US");
// show static ip fields
wm.setRestorePersistent(true);
wm.setSaveConfigCallback(saveWifiCallback);
wm.setSaveParamsCallback(saveParamCallback);
wm.setSaveConfigCallback(saveConfigCallback);
wm.setTitle("EcoFarm");
wm.setShowPassword(true);
wm.setShowStaticFields(true);
wm.setShowDnsFields(true);
//wm.setBreakAfterConfig(true);
// set AP static ip
//wm.setSTAStaticIPConfig(IPAddress(192,168,1,150), IPAddress(192,168,1,1), IPAddress(255,255,255,0));
// connect after portal save toggle
//wm.setSaveConnect(false); // connect, not only save
bool res;
res = wm.autoConnect("EcoFarm","123456789"); // password protected ap
if(!res) {
Serial.println("Failed to connect");
//ESP.restart();
}
else {
//if you get here you have connected to the WiFi
//wm.setSaveConnect(true);
Serial.println("connected... :)");
}
}

void loop() {
// put your main code here, to run repeatedly:
}

#####################################################################

Hardware

WiFimanager Branch/Release: Master
Hardware:Esp32:

Description

i have a problem when setting up configurations for Static IP from the Portal, its connected successfully but after reset the ESP32 or re-plug power its connected with WIFI creditial with Dynamic IP not with the Static IP Credentials that i inserted before.

so how i can save the StaticIP Credentials when i power the ESP32 again ??

Settings in IDE

Debug Messages

this message running after Setting up Wifi Credintial from the Portal

*wm:[1] Free heap: 280356
*wm:[1] ESP SDK version: v3.3.5-1-g85c43024c
*wm:[1] AutoConnect
*wm:[1] No Credentials are Saved, skipping connect
*wm:[2] Starting Config Portal
*wm:[2] AccessPoint set password is VALID
*wm:[2] Disabling STA
*wm:[2] Enabling AP
*wm:[1] StartAP with SSID: EcoFarm
*wm:[1] AP IP address: 192.168.4.1
*wm:[2] WiFiSetCountry to US
*wm:[2] [OK] esp_wifi_set_country: US
*wm:[1] Starting Web Portal
*wm:[2] HTTP server started
*wm:[2] Config Portal Running, blocking, waiting for clients...
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- HTTP Root
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- HTTP Root
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- HTTP Wifi
*wm:[2] WiFi Scan SYNC started
*wm:[2] WiFi Scan completed in 1843 ms
*wm:[1] 2 networks found
*wm:[2] AP: -76 Bishtawi-2.4
*wm:[2] AP: -88 Bishtawi 2
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- Request redirected to captive portal
*wm:[2] NUM CLIENTS: 1
*wm:[2] <- Request redirected to captive portal
*wm:[2] <- HTTP WiFi save
[CALLBACK] saveParamCallback fired
*wm:[2] processing save
*wm:[2] Connecting as wifi client...
*wm:[2] Custom static IP/GW/Subnet/DNS
*wm:[2] Custom static DNS
*wm:[1] STA IP set: 192.168.1.153
*wm:[1] Connecting to NEW AP: Bishtawi-2.4
*wm:[1] connectTimeout not set, ESP waitForConnectResult...
*wm:[2] Connection result: WL_CONNECTED
*wm:[1] Connect to new AP [SUCCESS]
*wm:[1] Got IP Address:
*wm:[1] 192.168.1.153
Should save config
*wm:[2] shutdownConfigPortal
*wm:[2] <- Request redirected to captive portal
*wm:[0] [ERROR] disconnect configportal - softAPdisconnect FAILED
*wm:[2] restoring usermode STA
*wm:[2] wifi status: WL_CONNECTED
*wm:[2] wifi mode: STA
*wm:[2] configportal closed
*wm:[1] config portal exiting
connected... :)

WiFi connected!
IP address: 192.168.1.153
ESP Mac Address: 94:B9:7E:EA:A0:30
Subnet Mask: 255.255.255.0
Gateway IP: 192.168.1.1
DNS: 8.8.8.8

################ and this the results after restart or re-power the ESP32

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:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5856
entry 0x400806a8
*wm:[1] Free heap: 280380
*wm:[1] ESP SDK version: v3.3.5-1-g85c43024c
*wm:[1] AutoConnect
*wm:[2] WiFiSetCountry to US
*wm:[2] [OK] esp_wifi_set_country: US
*wm:[2] ESP32 event handler enabled
*wm:[2] Connecting as wifi client...
*wm:[2] Custom static IP/GW/Subnet/DNS
*wm:[2] Custom STA IP/GW/Subnet
*wm:[1] STA IP set: 192.168.1.150
*wm:[1] Connecting to SAVED AP: Bishtawi-2.4
*wm:[1] connectTimeout not set, ESP waitForConnectResult...
*wm:[2] Connection result: WL_CONNECTED
*wm:[1] AutoConnect: SUCCESS
*wm:[1] STA IP Address: 192.168.1.150
connected... :)

WiFi connected!
IP address: 192.168.1.150
ESP Mac Address: 94:B9:7E:EA:A0:30
Subnet Mask: 255.255.255.0
Gateway IP: 192.168.1.1
DNS: 0.0.0.0

Originally created by @learn05 on GitHub (Nov 8, 2021). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1308 #include <WiFiManager.h> // Define the Wifi Manager Params WiFiManager wm; void saveParamCallback(){ Serial.println("[CALLBACK] saveParamCallback fired"); // wm.stopConfigPortal(); } void saveWifiCallback(){ Serial.println("[CALLBACK] saveCallback fired"); } //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 setup() { WiFi.mode(WIFI_STA); Serial.begin(115200); wm.debugPlatformInfo(); wm.setCountry("US"); // show static ip fields wm.setRestorePersistent(true); wm.setSaveConfigCallback(saveWifiCallback); wm.setSaveParamsCallback(saveParamCallback); wm.setSaveConfigCallback(saveConfigCallback); wm.setTitle("EcoFarm"); wm.setShowPassword(true); wm.setShowStaticFields(true); wm.setShowDnsFields(true); //wm.setBreakAfterConfig(true); // set AP static ip //wm.setSTAStaticIPConfig(IPAddress(192,168,1,150), IPAddress(192,168,1,1), IPAddress(255,255,255,0)); // connect after portal save toggle //wm.setSaveConnect(false); // connect, not only save bool res; res = wm.autoConnect("EcoFarm","123456789"); // password protected ap if(!res) { Serial.println("Failed to connect"); //ESP.restart(); } else { //if you get here you have connected to the WiFi //wm.setSaveConnect(true); Serial.println("connected... :)"); } } void loop() { // put your main code here, to run repeatedly: } ##################################################################### #### Hardware WiFimanager Branch/Release: Master Hardware:Esp32: ### Description i have a problem when setting up configurations for Static IP from the Portal, its connected successfully but after reset the ESP32 or re-plug power its connected with WIFI creditial with Dynamic IP not with the Static IP Credentials that i inserted before. so how i can save the StaticIP Credentials when i power the ESP32 again ?? ### Settings in IDE ### Debug Messages ##### this message running after Setting up Wifi Credintial from the Portal *wm:[1] Free heap: 280356 *wm:[1] ESP SDK version: v3.3.5-1-g85c43024c *wm:[1] AutoConnect *wm:[1] No Credentials are Saved, skipping connect *wm:[2] Starting Config Portal *wm:[2] AccessPoint set password is VALID *wm:[2] Disabling STA *wm:[2] Enabling AP *wm:[1] StartAP with SSID: EcoFarm *wm:[1] AP IP address: 192.168.4.1 *wm:[2] WiFiSetCountry to US *wm:[2] [OK] esp_wifi_set_country: US *wm:[1] Starting Web Portal *wm:[2] HTTP server started *wm:[2] Config Portal Running, blocking, waiting for clients... *wm:[2] <- Request redirected to captive portal *wm:[2] <- HTTP Root *wm:[2] <- Request redirected to captive portal *wm:[2] <- HTTP Root *wm:[2] <- Request redirected to captive portal *wm:[2] <- Request redirected to captive portal *wm:[2] <- HTTP Wifi *wm:[2] WiFi Scan SYNC started *wm:[2] WiFi Scan completed in 1843 ms *wm:[1] 2 networks found *wm:[2] AP: -76 Bishtawi-2.4 *wm:[2] AP: -88 Bishtawi 2 *wm:[2] <- Request redirected to captive portal *wm:[2] <- Request redirected to captive portal *wm:[2] <- Request redirected to captive portal *wm:[2] NUM CLIENTS: 1 *wm:[2] <- Request redirected to captive portal *wm:[2] <- HTTP WiFi save [CALLBACK] saveParamCallback fired *wm:[2] processing save *wm:[2] Connecting as wifi client... *wm:[2] Custom static IP/GW/Subnet/DNS *wm:[2] Custom static DNS *wm:[1] STA IP set: 192.168.1.153 *wm:[1] Connecting to NEW AP: Bishtawi-2.4 *wm:[1] connectTimeout not set, ESP waitForConnectResult... *wm:[2] Connection result: WL_CONNECTED *wm:[1] Connect to new AP [SUCCESS] *wm:[1] Got IP Address: *wm:[1] 192.168.1.153 Should save config *wm:[2] shutdownConfigPortal *wm:[2] <- Request redirected to captive portal *wm:[0] [ERROR] disconnect configportal - softAPdisconnect FAILED *wm:[2] restoring usermode STA *wm:[2] wifi status: WL_CONNECTED *wm:[2] wifi mode: STA *wm:[2] configportal closed *wm:[1] config portal exiting connected... :) WiFi connected! IP address: 192.168.1.153 ESP Mac Address: 94:B9:7E:EA:A0:30 Subnet Mask: 255.255.255.0 Gateway IP: 192.168.1.1 DNS: 8.8.8.8 ################ and this the results after restart or re-power the ESP32 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:1 load:0x3fff0018,len:4 load:0x3fff001c,len:1044 load:0x40078000,len:10124 load:0x40080400,len:5856 entry 0x400806a8 *wm:[1] Free heap: 280380 *wm:[1] ESP SDK version: v3.3.5-1-g85c43024c *wm:[1] AutoConnect *wm:[2] WiFiSetCountry to US *wm:[2] [OK] esp_wifi_set_country: US *wm:[2] ESP32 event handler enabled *wm:[2] Connecting as wifi client... *wm:[2] Custom static IP/GW/Subnet/DNS *wm:[2] Custom STA IP/GW/Subnet *wm:[1] STA IP set: 192.168.1.150 *wm:[1] Connecting to SAVED AP: Bishtawi-2.4 *wm:[1] connectTimeout not set, ESP waitForConnectResult... *wm:[2] Connection result: WL_CONNECTED *wm:[1] AutoConnect: SUCCESS *wm:[1] STA IP Address: 192.168.1.150 connected... :) WiFi connected! IP address: 192.168.1.150 ESP Mac Address: 94:B9:7E:EA:A0:30 Subnet Mask: 255.255.255.0 Gateway IP: 192.168.1.1 DNS: 0.0.0.0
Author
Owner

@johnsmakar commented on GitHub (Mar 10, 2022):

I also have this question, were you ever able to figure this out?

<!-- gh-comment-id:1064269918 --> @johnsmakar commented on GitHub (Mar 10, 2022): I also have this question, were you ever able to figure this out?
Author
Owner

@tablatronix commented on GitHub (Mar 10, 2022):

you can save it in filesystem like other parameters

<!-- gh-comment-id:1064438174 --> @tablatronix commented on GitHub (Mar 10, 2022): you can save it in filesystem like other parameters
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#1121
No description provided.