tzapu / WiFiManager

ESP8266 WiFi Connection manager with web captive portal
http://tzapu.com/esp8266-wifi-connection-manager-library-arduino-ide/
MIT License
6.55k stars 1.97k forks source link

How to save/load a static IP field ? #1627

Open julian-lp opened 1 year ago

julian-lp commented 1 year ago

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 :)");
    }
julian-lp commented 1 year ago

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);
woodenplastic commented 1 year ago

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.

tablatronix commented 1 year ago

I think you have to save and load static yourself