[GH-ISSUE #856] Static IP wrong connection fix #722

Open
opened 2026-02-28 01:26:45 +03:00 by kerem · 14 comments
Owner

Originally created by @dzanis on GitHub (Mar 22, 2019).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/856

Hi. I got the problem of static IP .If you enter it incorrectly or if the router is turned on DHCP, then even if you remove the settings of the static address, it still connects to it. Solved the problem before wifi connection enter WiFi.config(IPAddress(NULL), IPAddress(NULL), IPAddress(NULL));
Then added a condition to the code

github.com/tzapu/WiFiManager@740005b21e/WiFiManager.cpp (L280)

 if (_sta_static_ip) {
    DEBUG_WM(F("Custom STA IP/GW/Subnet"));
    WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn);
    DEBUG_WM(WiFi.localIP());
  }
else
{
WiFi.config(IPAddress(NULL), IPAddress(NULL), IPAddress(NULL))
}
Originally created by @dzanis on GitHub (Mar 22, 2019). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/856 Hi. I got the problem of static IP .If you enter it incorrectly or if the router is turned on DHCP, then even if you remove the settings of the static address, it still connects to it. Solved the problem before wifi connection enter `WiFi.config(IPAddress(NULL), IPAddress(NULL), IPAddress(NULL)); ` Then added a condition to the code https://github.com/tzapu/WiFiManager/blob/740005b21e5f5e5c6092dbd4d3037e4edee19113/WiFiManager.cpp#L280 ``` if (_sta_static_ip) { DEBUG_WM(F("Custom STA IP/GW/Subnet")); WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn); DEBUG_WM(WiFi.localIP()); } else { WiFi.config(IPAddress(NULL), IPAddress(NULL), IPAddress(NULL)) } ```
Author
Owner

@sorriso93 commented on GitHub (Apr 1, 2019):

Is it possible to configure also DNS with staticip config?

<!-- gh-comment-id:478773598 --> @sorriso93 commented on GitHub (Apr 1, 2019): Is it possible to configure also DNS with staticip config?
Author
Owner

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

What do you mean “remove the settings”?

<!-- gh-comment-id:478776021 --> @tablatronix commented on GitHub (Apr 1, 2019): What do you mean “remove the settings”?
Author
Owner

@dzanis commented on GitHub (Apr 2, 2019):

If you incorrectly enter the address of the router, then do not connect until you delete the static ip settings can not connect.

<!-- gh-comment-id:479077387 --> @dzanis commented on GitHub (Apr 2, 2019): If you incorrectly enter the address of the router, then do not connect until you delete the static ip settings can not connect.
Author
Owner

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

I still do not understand can you explain in detailed steps to reproduce.

Can you not change or remove the static settings in the portal ?

<!-- gh-comment-id:479136382 --> @tablatronix commented on GitHub (Apr 2, 2019): I still do not understand can you explain in detailed steps to reproduce. Can you not change or remove the static settings in the portal ?
Author
Owner

@dzanis commented on GitHub (Apr 6, 2019):

Yes, I can not change the static settings on the portal, if DHTP is enabled on the router. I decided to make it easier to use the scanner ip address to find what address the esp was connected to

<!-- gh-comment-id:480516751 --> @dzanis commented on GitHub (Apr 6, 2019): Yes, I can not change the static settings on the portal, if DHTP is enabled on the router. I decided to make it easier to use the scanner ip address to find what address the esp was connected to
Author
Owner

@tablatronix commented on GitHub (Apr 6, 2019):

I have no idea what you are doing. You should be able to just delete static ip settings if not using them and just use dhcp, where is the problem actually occuring?

<!-- gh-comment-id:480543320 --> @tablatronix commented on GitHub (Apr 6, 2019): I have no idea what you are doing. You should be able to just delete static ip settings if not using them and just use dhcp, where is the problem actually occuring?
Author
Owner

@dzanis commented on GitHub (Apr 6, 2019):

Of course, I can delete static ip settings in the code. The problem is that without a pre-project this cannot be done.

<!-- gh-comment-id:480543652 --> @dzanis commented on GitHub (Apr 6, 2019): Of course, I can delete static ip settings in the code. The problem is that without a pre-project this cannot be done.
Author
Owner

@tablatronix commented on GitHub (Apr 7, 2019):

Right so what exactly happens when you erase in portal?? You say it still uses it, can you add a toggle or something?

<!-- gh-comment-id:480547743 --> @tablatronix commented on GitHub (Apr 7, 2019): Right so what exactly happens when you erase in portal?? You say it still uses it, can you add a toggle or something?
Author
Owner

@dzanis commented on GitHub (Apr 7, 2019):

You can enter the AP MODE only by turning off the router. After you can reconnect the connection. But after you entered the wrong static ip, it will no longer connect to the network again, even with the correct settings. The problem is solved only if you change the ssid in the router.

<!-- gh-comment-id:480589268 --> @dzanis commented on GitHub (Apr 7, 2019): You can enter the AP MODE only by turning off the router. After you can reconnect the connection. But after you entered the wrong static ip, it will no longer connect to the network again, even with the correct settings. The problem is solved only if you change the ssid in the router.
Author
Owner

@tablatronix commented on GitHub (Apr 7, 2019):

you can enter the ap mode whenever you want if you add a button or something to do it, or add an erase config method,

I will have to test this cause I still am not getting the whole picture.

So if you have a short sketch or example.

Do you think the esp is remembering the static ip ?

Or do you think the web form is not saving when it is empty ?

<!-- gh-comment-id:480593244 --> @tablatronix commented on GitHub (Apr 7, 2019): you can enter the ap mode whenever you want if you add a button or something to do it, or add an erase config method, I will have to test this cause I still am not getting the whole picture. So if you have a short sketch or example. Do you think the esp is remembering the static ip ? Or do you think the web form is not saving when it is empty ?
Author
Owner

@dzanis commented on GitHub (Apr 7, 2019):

If incorrectly entered static IP,then I will go through the access point to change the connection,settings are not reset, the output shows
Already connected. Bailing out.
Because the previous settings are reset only if connected, in this place the code
github.com/tzapu/WiFiManager@740005b21e/WiFiManager.cpp (L201)

To reset the previous settings, you need to erase the settings. But they do not erase until you connect. That's why you need to connect to another network. But not everyone has a few open networks. For example, I have one. And I cannot connect to my own because the static ip address for it was incorrectly configured.
Ansvers:
The sketch is too big, if I separate it, I can show it.
It turns out that he remembers.
web form is fine.

<!-- gh-comment-id:480598189 --> @dzanis commented on GitHub (Apr 7, 2019): If incorrectly entered static IP,then I will go through the access point to change the connection,settings are not reset, the output shows `Already connected. Bailing out.` Because the previous settings are reset only if connected, in this place the code https://github.com/tzapu/WiFiManager/blob/740005b21e5f5e5c6092dbd4d3037e4edee19113/WiFiManager.cpp#L201 To reset the previous settings, you need to erase the settings. But they do not erase until you connect. That's why you need to connect to another network. But not everyone has a few open networks. For example, I have one. And I cannot connect to my own because the static ip address for it was incorrectly configured. Ansvers: The sketch is too big, if I separate it, I can show it. It turns out that he remembers. web form is fine.
Author
Owner

@dzanis commented on GitHub (Apr 7, 2019):

I decided that it is better not to use a static address, because many routers are enabled DHCP
It's easier to find the address of the esp program https://github.com/dzanis/IPScanner

<!-- gh-comment-id:480599074 --> @dzanis commented on GitHub (Apr 7, 2019): I decided that it is better not to use a static address, because many routers are enabled DHCP It's easier to find the address of the esp program https://github.com/dzanis/IPScanner
Author
Owner

@tablatronix commented on GitHub (Apr 7, 2019):

Oh you are still using master branch? Yeah that is a known issue if the wifi is the same it just ignores the save

<!-- gh-comment-id:480606639 --> @tablatronix commented on GitHub (Apr 7, 2019): Oh you are still using master branch? Yeah that is a known issue if the wifi is the same it just ignores the save
Author
Owner

@Berzegeri commented on GitHub (Apr 20, 2019):

Is it possible to configure also DNS with staticip config?

Hi,
yes, but it's redundant a bit...
After you set the static IP, only thing you need to do is to set it with WiFi.config().

in setup:
WiFiManager wifiManager;
wifiManager.setSTAStaticIPConfig(IPAddress(192,168,0,110), IPAddress(192,168,0,1), IPAddress(255,255,255,0));
WiFi.config(ip,gateway,subnet,dns1,dns2);

<!-- gh-comment-id:485128929 --> @Berzegeri commented on GitHub (Apr 20, 2019): > Is it possible to configure also DNS with staticip config? Hi, yes, but it's redundant a bit... After you set the static IP, only thing you need to do is to set it with WiFi.config(). in setup: `WiFiManager wifiManager;` `wifiManager.setSTAStaticIPConfig(IPAddress(192,168,0,110), IPAddress(192,168,0,1), IPAddress(255,255,255,0));` `WiFi.config(ip,gateway,subnet,dns1,dns2);`
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#722
No description provided.