[GH-ISSUE #1627] How to save/load a static IP field ? #1386

Open
opened 2026-02-28 01:29:52 +03:00 by kerem · 3 comments
Owner

Originally created by @julian-lp on GitHub (Jun 17, 2023).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1627

I've been trying to save the static ip that I want to be assigned to the esp32 (the device will be used somewhere else and I'll not have access to its serial port to know its IP if it's done dynamically)

The configuration portal has one field whose name is Static IP, but I'm unclear how can I get that field and use in the line

wm.setSTAStaticIPConfig(IPAddress(CONF_IP_LOCAL), IPAddress(CONF_IP_DEFAULT_GATEWAY), IPAddress(CONF_IP_SUBNET));

I'm wondering if that line is executed once the config portal has ran and the wi-fi autentication occurs, or the ip is set even if there's no valid credentials, ... I mean, I'd like it to be:
1-run the portal
2-set net ID, password and Static IP
3-save that static IP in eeprom (flash) << ID and password is managed by wi fi manager but dont know about the IP ????
4-before the wi fi manager tries to connect to wi-fi, load that static IP I've set in config portal

cause it is clear that it's me who is setting 192,168,1,177 IP rather the one I entered by the config portal

Sorry for my english, hope I explained the issue almost well


#define CONF_IP_LOCAL 192,168,1,177    
#define CONF_IP_DEFAULT_GATEWAY 192,168,1,1  
#define CONF_IP_SUBNET 255,255,255,0 
#define CONF_SSID_INICIAL "ESP32"
#define CONF_PASS_INICIAL "ABC123456"



//in the following line I want to use the ip set in the config portal
wm.setSTAStaticIPConfig(IPAddress(CONF_IP_LOCAL), IPAddress(CONF_IP_DEFAULT_GATEWAY), IPAddress(CONF_IP_SUBNET));

    res = wm.autoConnect(CONF_SSID_INICIAL,CONF_PASS_INICIAL); // password protected ap

    if(!res){
        Serial.println("Failed to connect");
        //ESP.restart();
    }else{
        //if you get here you have connected to the WiFi    
        Serial.println("CONNECTED :)");
    }


Originally created by @julian-lp on GitHub (Jun 17, 2023). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1627 I've been trying to save the static ip that I want to be assigned to the esp32 (the device will be used somewhere else and I'll not have access to its serial port to know its IP if it's done dynamically) The configuration portal has one field whose name is Static IP, but I'm unclear how can I get that field and use in the line ```cpp wm.setSTAStaticIPConfig(IPAddress(CONF_IP_LOCAL), IPAddress(CONF_IP_DEFAULT_GATEWAY), IPAddress(CONF_IP_SUBNET)); ``` I'm wondering if that line is executed once the config portal has ran and the wi-fi autentication occurs, or the ip is set even if there's no valid credentials, ... I mean, I'd like it to be: 1-run the portal 2-set net ID, password and Static IP 3-save that static IP in eeprom (flash) << ID and password is managed by wi fi manager but dont know about the IP ???? 4-before the wi fi manager tries to connect to wi-fi, load that static IP I've set in config portal cause it is clear that it's me who is setting 192,168,1,177 IP rather the one I entered by the config portal Sorry for my english, hope I explained the issue almost well ```cpp #define CONF_IP_LOCAL 192,168,1,177 #define CONF_IP_DEFAULT_GATEWAY 192,168,1,1 #define CONF_IP_SUBNET 255,255,255,0 #define CONF_SSID_INICIAL "ESP32" #define CONF_PASS_INICIAL "ABC123456" //in the following line I want to use the ip set in the config portal wm.setSTAStaticIPConfig(IPAddress(CONF_IP_LOCAL), IPAddress(CONF_IP_DEFAULT_GATEWAY), IPAddress(CONF_IP_SUBNET)); res = wm.autoConnect(CONF_SSID_INICIAL,CONF_PASS_INICIAL); // password protected ap if(!res){ Serial.println("Failed to connect"); //ESP.restart(); }else{ //if you get here you have connected to the WiFi Serial.println("CONNECTED :)"); } ```
Author
Owner

@julian-lp commented on GitHub (Jun 19, 2023):

Well, I keep investigating a little bit and I found this:

If I include this line

wm.setSTAStaticIPConfig(IPAddress(CONF_IP_LOCAL), IPAddress(CONF_IP_DEFAULT_GATEWAY), IPAddress(CONF_IP_SUBNET));

then those fields (static IP, gateway and subnet) appears in the config portal. Otherwise, if the line isn't included, those fields arent visible in the config portal.

Now... how can I get the values of those fields ???(in order to save them to flash and retrieve every time the esp boots), given the fact that they are not "additional parameters" such as

WiFiManagerParameter parameter("parameterId", "Label", "default value", 40);
<!-- gh-comment-id:1596324235 --> @julian-lp commented on GitHub (Jun 19, 2023): Well, I keep investigating a little bit and I found this: If I include this line ```cpp wm.setSTAStaticIPConfig(IPAddress(CONF_IP_LOCAL), IPAddress(CONF_IP_DEFAULT_GATEWAY), IPAddress(CONF_IP_SUBNET)); ``` then those fields (static IP, gateway and subnet) appears in the config portal. Otherwise, if the line isn't included, those fields arent visible in the config portal. Now... how can I get the values of those fields ???(in order to save them to flash and retrieve every time the esp boots), given the fact that they are not "additional parameters" such as ```cpp WiFiManagerParameter parameter("parameterId", "Label", "default value", 40); ```
Author
Owner

@woodenplastic commented on GitHub (Sep 26, 2023):

In Setup of your sketch:

//wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
wm.setShowStaticFields(false);
wm.setShowDnsFields(false);

Set the fields to true and they show up. Saving is handled by WM in eeprom.

<!-- gh-comment-id:1735021157 --> @woodenplastic commented on GitHub (Sep 26, 2023): In Setup of your sketch: //wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); wm.setShowStaticFields(false); wm.setShowDnsFields(false); Set the fields to true and they show up. Saving is handled by WM in eeprom.
Author
Owner

@tablatronix commented on GitHub (Sep 29, 2023):

I think you have to save and load static yourself

<!-- gh-comment-id:1741556380 --> @tablatronix commented on GitHub (Sep 29, 2023): I think you have to save and load static yourself
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#1386
No description provided.