[GH-ISSUE #1578] Question: Saving Static IP #1345

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

Originally created by @lmcbmai on GitHub (Mar 28, 2023).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1578

Hi,
I am very new to WiFiManager and having troubles understanding whether static IP/Gateway/Netmask/DNS values are saved automatically after exiting the portal, or I need to write a code to make them survive power cycle or restart of ESP8266. I tried many code examples published here and I am seeing that SSID and Password values are saved but IPs are not. If additional steps are required to save IPs, I'd appreciate if somebody shares a code snippet or a link to an example showing how to do it.
Thanks

Originally created by @lmcbmai on GitHub (Mar 28, 2023). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1578 Hi, I am very new to WiFiManager and having troubles understanding whether static IP/Gateway/Netmask/DNS values are saved automatically after exiting the portal, or I need to write a code to make them survive power cycle or restart of ESP8266. I tried many code examples published here and I am seeing that SSID and Password values are saved but IPs are not. If additional steps are required to save IPs, I'd appreciate if somebody shares a code snippet or a link to an example showing how to do it. Thanks
kerem 2026-02-28 01:29:41 +03:00
  • closed this issue
  • added the
    Question
    label
Author
Owner

@Bighoneypot commented on GitHub (Mar 29, 2023):

Do you want to configure your device without dhcp?
That is, do you want to manually configure the IP address etc etc?

<!-- gh-comment-id:1488340280 --> @Bighoneypot commented on GitHub (Mar 29, 2023): Do you want to configure your device without dhcp? That is, do you want to manually configure the IP address etc etc?
Author
Owner

@Bighoneypot commented on GitHub (Mar 29, 2023):

You need similar this?
image

<!-- gh-comment-id:1488354174 --> @Bighoneypot commented on GitHub (Mar 29, 2023): You need similar this? ![image](https://user-images.githubusercontent.com/35570068/228508520-be62349e-f7ea-4954-9e8c-c17fbb09c85d.png)
Author
Owner

@lmcbmai commented on GitHub (Mar 29, 2023):

I want to configure device with static IP. My observation is that unlike SSID and Password, the values of Static IP and other 3 related fields are not saved; they are lost after power cycling or resetting the microcontroller.
Yesterday I wrote a code saving these 4 values in a file in LittleFS and loading them on power up. It is working fine now, and my only remaining question is - do I really need to write my own code to save static IP and related fields, or WiFiManager can do it and I simply do not know how to enable/call this feature.
Thanks

<!-- gh-comment-id:1488992142 --> @lmcbmai commented on GitHub (Mar 29, 2023): I want to configure device with static IP. My observation is that unlike SSID and Password, the values of Static IP and other 3 related fields are not saved; they are lost after power cycling or resetting the microcontroller. Yesterday I wrote a code saving these 4 values in a file in LittleFS and loading them on power up. It is working fine now, and my only remaining question is - do I really need to write my own code to save static IP and related fields, or WiFiManager can do it and I simply do not know how to enable/call this feature. Thanks
Author
Owner

@delugeia commented on GitHub (Mar 29, 2023):

I know this doesn't answer your question, but I have preferred to set the Static IP at the router level using a DHCP IP Reservation.

After connecting to the device using the normal WiFiManager process, I'm able to (in my case with Google Nest WiFi) go to Settings, Advanced Networking, DHCP IP Reservations. From there I can simply assign/change the IP address I want for the device's corresponding MAC address. Likewise, I can set port forwarding if I want the device to be accessible outside of my LAN.

There have always been similar features on every router I've used.

Hope this helps.

<!-- gh-comment-id:1489165169 --> @delugeia commented on GitHub (Mar 29, 2023): I know this doesn't answer your question, but I have preferred to set the Static IP at the router level using a DHCP IP Reservation. After connecting to the device using the normal WiFiManager process, I'm able to (in my case with Google Nest WiFi) go to Settings, Advanced Networking, DHCP IP Reservations. From there I can simply assign/change the IP address I want for the device's corresponding MAC address. Likewise, I can set port forwarding if I want the device to be accessible outside of my LAN. There have always been similar features on every router I've used. Hope this helps.
Author
Owner

@lmcbmai commented on GitHub (Mar 29, 2023):

@delugeia Thanks for your suggestions. That's the right (professional) way of doing things and I am all for it. Unfortunately in some cases that is not possible. For example I have 5G based wireless Internet and 5G modem I got from my ISP is integrated with WiFi router that has extremely limited list of configurable options. I cannot even set the local subnet of my choice, leave alone assigning static IPs to particular clients. Since there is no way to change the netmask, I reduced DHCP pool and using upper IPs outside pool range as static. Adding another WiFi router would be an option, but I don't want to overcomplicate things if not absolutely necessary.

<!-- gh-comment-id:1489338356 --> @lmcbmai commented on GitHub (Mar 29, 2023): @delugeia Thanks for your suggestions. That's the right (professional) way of doing things and I am all for it. Unfortunately in some cases that is not possible. For example I have 5G based wireless Internet and 5G modem I got from my ISP is integrated with WiFi router that has extremely limited list of configurable options. I cannot even set the local subnet of my choice, leave alone assigning static IPs to particular clients. Since there is no way to change the netmask, I reduced DHCP pool and using upper IPs outside pool range as static. Adding another WiFi router would be an option, but I don't want to overcomplicate things if not absolutely necessary.
Author
Owner

@delugeia commented on GitHub (Mar 29, 2023):

I completely understand. Was just an idea.

Sorry to hear about your limited setup. That would drive me bonkers. Actually, it did nearly drive me bonkers years ago when I was in a similar situation with a cable internet provider. They would change things so frequently and you couldn't do what I suggested with their system either. Before switching providers, I did take the route of purchasing my own intelligent router and just let their router believe there was only one, wired connection and it was on the DMZ.

Not to beat a dead horse, but there are some pretty good, inexpensive routers out there that will do the trick and give you a nice local network as well.

Best of luck.

<!-- gh-comment-id:1489401700 --> @delugeia commented on GitHub (Mar 29, 2023): I completely understand. Was just an idea. Sorry to hear about your limited setup. That would drive me bonkers. Actually, it did nearly drive me bonkers years ago when I was in a similar situation with a cable internet provider. They would change things so frequently and you couldn't do what I suggested with their system either. Before switching providers, I did take the route of purchasing my own intelligent router and just let their router believe there was only one, wired connection and it was on the DMZ. Not to beat a dead horse, but there are some pretty good, inexpensive routers out there that will do the trick and give you a nice local network as well. Best of luck.
Author
Owner

@tablatronix commented on GitHub (Mar 30, 2023):

Wm does not save anything to any part of flash by design. There are examples already do these things in user code

<!-- gh-comment-id:1490627025 --> @tablatronix commented on GitHub (Mar 30, 2023): Wm does not save anything to any part of flash by design. There are examples already do these things in user code
Author
Owner

@lmcbmai commented on GitHub (Apr 1, 2023):

@tablatronix Thanks for clarifying, but than do you know by any chance which other library saves SSID and Password? They somehow survive restarts nevertheless I am not doing anything to save and restore them.
In fact I just found in AutoConnectNonBlocking example the following lines:

    //automatically connect using saved credentials if they exist
    //If connection fails it starts an access point with the specified name
    if(wm.autoConnect("AutoConnectAP")){

This means credentials are saved somehow.
Thanks

<!-- gh-comment-id:1492754041 --> @lmcbmai commented on GitHub (Apr 1, 2023): @tablatronix Thanks for clarifying, but than do you know by any chance which other library saves SSID and Password? They somehow survive restarts nevertheless I am not doing anything to save and restore them. In fact I just found in AutoConnectNonBlocking example the following lines: ``` //automatically connect using saved credentials if they exist //If connection fails it starts an access point with the specified name if(wm.autoConnect("AutoConnectAP")){ ``` This means credentials are saved somehow. Thanks
Author
Owner

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

Credentials are saved by the esp library wm doesnt have to handle that

<!-- gh-comment-id:1493076775 --> @tablatronix commented on GitHub (Apr 1, 2023): Credentials are saved by the esp library wm doesnt have to handle that
Author
Owner

@LewiLim commented on GitHub (Jun 13, 2023):

You need similar this? image

Hi, is there an examples like this

<!-- gh-comment-id:1589108532 --> @LewiLim commented on GitHub (Jun 13, 2023): > You need similar this? ![image](https://user-images.githubusercontent.com/35570068/228508520-be62349e-f7ea-4954-9e8c-c17fbb09c85d.png) Hi, is there an examples like this
Author
Owner

@tablatronix commented on GitHub (Jun 13, 2023):

I believe there is one in the examples with spiffs, there is a litttlefs example but it does not include params

<!-- gh-comment-id:1589832195 --> @tablatronix commented on GitHub (Jun 13, 2023): I believe there is one in the examples with spiffs, there is a litttlefs example but it does not include params
Author
Owner

@debbyagestira commented on GitHub (Apr 3, 2024):

@Bighoneypot, @tablatronix Hello, how do I make those fields blank?

I have tried to delete the hardcoded values like this:

char static_ip[16];
char static_gw[16];
char static_sn[16];

or

char static_ip[16] = "";
char static_gw[16] = "";
char static_sn[16] = "";

but the fields/forms is gone..

before
IMG_20240403_090854
after
IMG_20240403_090906

You need similar this? image

<!-- gh-comment-id:2033434458 --> @debbyagestira commented on GitHub (Apr 3, 2024): @Bighoneypot, @tablatronix Hello, how do I make those fields blank? I have tried to delete the hardcoded values like this: ``` char static_ip[16]; char static_gw[16]; char static_sn[16]; ``` or ``` char static_ip[16] = ""; char static_gw[16] = ""; char static_sn[16] = ""; ``` but the fields/forms is gone.. >before ![IMG_20240403_090854](https://github.com/tzapu/WiFiManager/assets/73832877/4a4cdab2-5335-40bc-a6e9-fdcd678b7ea5) >after ![IMG_20240403_090906](https://github.com/tzapu/WiFiManager/assets/73832877/037dd201-f111-4219-b636-f95c61572f7d) > You need similar this? ![image](https://user-images.githubusercontent.com/35570068/228508520-be62349e-f7ea-4954-9e8c-c17fbb09c85d.png)
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#1345
No description provided.