[GH-ISSUE #719] ESP8266 static IP changes on reset. #601

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

Originally created by @bkrajendra on GitHub (Sep 3, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/719

----------------------------- Remove above -----------------------------

Basic Infos

Hardware

WiFimanager Branch/Release:

  • Master
  • Development 0.12

Esp8266/Esp32:

  • ESP8266
  • ESP32

Hardware: ESP-12e, esp01, esp25

  • ESP01
  • ESP12 E/F/S (nodemcu, wemos, feather)
  • Other

ESP Core Version: 2.4.0, staging

  • 2.3.0
  • 2.4.0
  • staging (master/dev)

Description

Problem description

Settings in IDE

Module: Generic

Additional libraries:

Sketch


#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <EEPROM.h>
#include <WiFiClient.h>
#include <DNSServer.h>
#include <ArduinoOTA.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager
#include <ESP8266mDNS.h>
#include <ESP8266SSDP.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
void setup() {
  // Captive Portal Starts #####################
  WiFiManager wifiManager;

  wifiManager.setTimeout(120);

  //Se the AP Static IP
  IPAddress _ip = IPAddress(10, 1, 104, 1);
  IPAddress _gw = IPAddress(10, 1, 104, 1);
  IPAddress _sn = IPAddress(255, 255, 255, 0);
  wifiManager.setAPStaticIPConfig(_ip, _gw, _sn);


  IPAddress _ip1, _gw1, _sn1, _dns1;
  _ip1.fromString("172.25.10.14");
  _gw1.fromString("172.25.1.1");
  _sn1.fromString("255.255.0.0");
  _dns1.fromString("8.8.8.8");
  //end-block1

  wifiManager.setSTAStaticIPConfig(_ip1, _gw1, _sn1, _dns1);

  //Goes into a blocking loop awaiting configuration
  if (!wifiManager.autoConnect("MyAPNAME", "12345678")) {
    Serial.println("failed to connect and hit timeout");
    delay(2000);
    ESP.restart();
    delay(2000);
  }

  Serial.println("Connected to local WiFI");
  Serial.print ("IP address:  ");
  Serial.println (WiFi.localIP());
  // Captive Portal Ends #####################

  MDNS.addService("http", "tcp", 80);
  if (MDNS.begin("MyAPNAME")) {
    Serial.println("MDNS responder started");
  }

}

void loop() {

}

I'm trying very simple setup with ESP-12E here. What I observe is that if I restart ESP by using reset pin, it gets random dynamic IP. But if I use software reset via programming or URL it get its static IP. Also mostly after power on it gets its static IP Properly. But I consistently observed that if I use hardware reset pin it gets IP by DHCP as it switches back to my normal IP assigned by WiFi router.

pardon me if i'm creating duplicate issue, but i searched for similar problem but could not find a trace of it in issues.
So what is going on wrong or am i missing something.

Edit:
Just tested and verified again with NodeMCU.
Find below the debug logs first is after after ESP.restart()
And second one is Hardware reset.

This is Version
BUILD_TAG: 1.1.2

[SETUP] BOOT WAIT 2...
[SETUP] BOOT WAIT 1...
*WM: AutoConnect 
*WM: Connecting as wifi client... 
*WM: Custom STA IP/GW/Subnet/DNS 
*WM: STA IP set: 10.1.25.30
*WM: Connecting to saved AP: anshul
*WM: connectTimeout not set, ESP waitForConnectResult... 
*WM: Connection result: WL_CONNECTED
*WM: AutoConnect: SUCCESS 
*WM: STA IP Address: 10.1.25.30
Connected to local WiFI
IP address:  10.1.25.30
MDNS responder started
HTTPserver started
SSDP Ready!
connecting mqtt client 
SWITCH811488731
MQTT connected!
Subscribed



After Hardware Reset
This is Version
BUILD_TAG: 1.1.2

[SETUP] BOOT WAIT 2...
[SETUP] BOOT WAIT 1...
*WM: AutoConnect 
*WM: AutoConnect: SUCCESS 
*WM: STA IP Address: 10.1.25.22
Connected to local WiFI
IP address:  10.1.25.22
MDNS responder started
HTTPserver started
SSDP Ready!
connecting mqtt client 
SWITCH811488731
MQTT connected!
Subscribed

Originally created by @bkrajendra on GitHub (Sep 3, 2018). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/719 ----------------------------- Remove above ----------------------------- ### Basic Infos #### Hardware **WiFimanager Branch/Release:** - [ ] Master - [x] Development 0.12 **Esp8266/Esp32:** - [x] ESP8266 - [ ] ESP32 **Hardware: ESP-12e, esp01, esp25** - [ ] ESP01 - [x] ESP12 E/F/S (nodemcu, wemos, feather) - [ ] Other **ESP Core Version: 2.4.0, staging** - [ ] 2.3.0 - [x] 2.4.0 - [ ] staging (master/dev) ### Description Problem description ### Settings in IDE Module: Generic Additional libraries: ### Sketch ```cpp #include <Arduino.h> #include <ESP8266WiFi.h> #include <EEPROM.h> #include <WiFiClient.h> #include <DNSServer.h> #include <ArduinoOTA.h> #include <ESP8266WebServer.h> #include <WiFiManager.h> //https://github.com/tzapu/WiFiManager #include <ESP8266mDNS.h> #include <ESP8266SSDP.h> #include <ESP8266HTTPClient.h> #include <ESP8266httpUpdate.h> void setup() { // Captive Portal Starts ##################### WiFiManager wifiManager; wifiManager.setTimeout(120); //Se the AP Static IP IPAddress _ip = IPAddress(10, 1, 104, 1); IPAddress _gw = IPAddress(10, 1, 104, 1); IPAddress _sn = IPAddress(255, 255, 255, 0); wifiManager.setAPStaticIPConfig(_ip, _gw, _sn); IPAddress _ip1, _gw1, _sn1, _dns1; _ip1.fromString("172.25.10.14"); _gw1.fromString("172.25.1.1"); _sn1.fromString("255.255.0.0"); _dns1.fromString("8.8.8.8"); //end-block1 wifiManager.setSTAStaticIPConfig(_ip1, _gw1, _sn1, _dns1); //Goes into a blocking loop awaiting configuration if (!wifiManager.autoConnect("MyAPNAME", "12345678")) { Serial.println("failed to connect and hit timeout"); delay(2000); ESP.restart(); delay(2000); } Serial.println("Connected to local WiFI"); Serial.print ("IP address: "); Serial.println (WiFi.localIP()); // Captive Portal Ends ##################### MDNS.addService("http", "tcp", 80); if (MDNS.begin("MyAPNAME")) { Serial.println("MDNS responder started"); } } void loop() { } ``` I'm trying very simple setup with ESP-12E here. What I observe is that if I restart ESP by using reset pin, it gets random dynamic IP. But if I use software reset via programming or URL it get its static IP. Also mostly after power on it gets its static IP Properly. But I consistently observed that if I use hardware reset pin it gets IP by DHCP as it switches back to my normal IP assigned by WiFi router. pardon me if i'm creating duplicate issue, but i searched for similar problem but could not find a trace of it in issues. So what is going on wrong or am i missing something. Edit: Just tested and verified again with NodeMCU. Find below the debug logs first is after after ESP.restart() And second one is Hardware reset. ``` This is Version BUILD_TAG: 1.1.2 [SETUP] BOOT WAIT 2... [SETUP] BOOT WAIT 1... *WM: AutoConnect *WM: Connecting as wifi client... *WM: Custom STA IP/GW/Subnet/DNS *WM: STA IP set: 10.1.25.30 *WM: Connecting to saved AP: anshul *WM: connectTimeout not set, ESP waitForConnectResult... *WM: Connection result: WL_CONNECTED *WM: AutoConnect: SUCCESS *WM: STA IP Address: 10.1.25.30 Connected to local WiFI IP address: 10.1.25.30 MDNS responder started HTTPserver started SSDP Ready! connecting mqtt client SWITCH811488731 MQTT connected! Subscribed After Hardware Reset This is Version BUILD_TAG: 1.1.2 [SETUP] BOOT WAIT 2... [SETUP] BOOT WAIT 1... *WM: AutoConnect *WM: AutoConnect: SUCCESS *WM: STA IP Address: 10.1.25.22 Connected to local WiFI IP address: 10.1.25.22 MDNS responder started HTTPserver started SSDP Ready! connecting mqtt client SWITCH811488731 MQTT connected! Subscribed ```
kerem 2026-02-28 01:26:10 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@tablatronix commented on GitHub (Sep 3, 2018):

erase flash ?

<!-- gh-comment-id:418113790 --> @tablatronix commented on GitHub (Sep 3, 2018): erase flash ?
Author
Owner

@tablatronix commented on GitHub (Sep 3, 2018):

#720

<!-- gh-comment-id:418114752 --> @tablatronix commented on GitHub (Sep 3, 2018): #720
Author
Owner

@bkrajendra commented on GitHub (Sep 3, 2018):

tried with option Erase Flash:All Flash Content.
But still the problem is there.
Now im updating again everything to latest dev version and will try once more.

<!-- gh-comment-id:418182918 --> @bkrajendra commented on GitHub (Sep 3, 2018): tried with option Erase Flash:All Flash Content. But still the problem is there. Now im updating again everything to latest dev version and will try once more.
Author
Owner

@bkrajendra commented on GitHub (Sep 3, 2018):

Updated WiFi Manager to latest dev branch.... no success
Updated ESP SDK to latest from git ... no success....
See the difference in log.
Static Ip configured is 10.1.25.30

With Software reset using ESP.restart():

WM: [1] AutoConnect 
*WM: [2] Connecting as wifi client... 
*WM: [2] Custom STA IP/GW/Subnet/DNS 
*WM: [1] STA IP set: 10.1.25.30
*WM: [3] WIFI station disconnect 
*WM: [1] Connecting to saved AP: anshul
*WM: [3] WiFi station enable 
*WM: [3] enableSTA PERSISTENT ON 
*WM: [1] connectTimeout not set, ESP waitForConnectResult... 
*WM: [2] Connection result: WL_CONNECTED
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [1] AutoConnect: SUCCESS 
*WM: [1] STA IP Address: 10.1.25.30
Connected to local WiFI
IP address:  10.1.25.30

With Hardware reset:

*WM: [1] AutoConnect 
*WM: [1] AutoConnect: SUCCESS 
*WM: [1] STA IP Address: 10.1.25.22
Connected to local WiFI
IP address:  10.1.25.22

<!-- gh-comment-id:418193692 --> @bkrajendra commented on GitHub (Sep 3, 2018): Updated WiFi Manager to latest dev branch.... no success Updated ESP SDK to latest from git ... no success.... See the difference in log. Static Ip configured is 10.1.25.30 With Software reset using ESP.restart(): ``` WM: [1] AutoConnect *WM: [2] Connecting as wifi client... *WM: [2] Custom STA IP/GW/Subnet/DNS *WM: [1] STA IP set: 10.1.25.30 *WM: [3] WIFI station disconnect *WM: [1] Connecting to saved AP: anshul *WM: [3] WiFi station enable *WM: [3] enableSTA PERSISTENT ON *WM: [1] connectTimeout not set, ESP waitForConnectResult... *WM: [2] Connection result: WL_CONNECTED *WM: [3] lastconxresult: WL_CONNECTED *WM: [1] AutoConnect: SUCCESS *WM: [1] STA IP Address: 10.1.25.30 Connected to local WiFI IP address: 10.1.25.30 ``` With Hardware reset: ``` *WM: [1] AutoConnect *WM: [1] AutoConnect: SUCCESS *WM: [1] STA IP Address: 10.1.25.22 Connected to local WiFI IP address: 10.1.25.22 ```
Author
Owner

@tablatronix commented on GitHub (Sep 4, 2018):

*WM: [1] AutoConnect 
*WM: [1] AutoConnect: ESP Already Connected 
*WM: [2] Custom STA IP/GW/Subnet/DNS 
*WM: [1] STA IP set: 172.25.10.14
*WM: [1] AutoConnect: SUCCESS 
*WM: [1] STA IP Address: 172.25.10.14
Connected to local WiFI
IP address:  172.25.10.14
MDNS responder started

*WM: [1] AutoConnect 
*WM: [2] Connecting as wifi client... 
*WM: [2] Custom STA IP/GW/Subnet/DNS 
*WM: [1] STA IP set: 172.25.10.14
*WM: [3] WIFI station disconnect 
*WM: [1] Connecting to saved AP: shawn
*WM: [3] WiFi station enable 
*WM: [3] enableSTA PERSISTENT ON 
*WM: [1] connectTimeout not set, ESP waitForConnectResult... 
*WM: [2] Connection result: WL_CONNECTED
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [1] AutoConnect: SUCCESS 
*WM: [1] STA IP Address: 172.25.10.14
Connected to local WiFI
IP address:  172.25.10.14
MDNS responder started

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v4ceabea9
~ld
*WM: [1] AutoConnect 
*WM: [2] Connecting as wifi client... 
*WM: [2] Custom STA IP/GW/Subnet/DNS 
*WM: [1] STA IP set: 172.25.10.14
*WM: [3] WIFI station disconnect 
*WM: [1] Connecting to saved AP: shawn
*WM: [3] WiFi station enable 
*WM: [3] enableSTA PERSISTENT ON 
*WM: [1] connectTimeout not set, ESP waitForConnectResult... 
*WM: [2] Connection result: WL_CONNECTED
*WM: [3] lastconxresult: WL_CONNECTED
*WM: [1] AutoConnect: SUCCESS 
*WM: [1] STA IP Address: 172.25.10.14
Connected to local WiFI
IP address:  172.25.10.14
MDNS responder started

This is what I get, looks ok to me.
Let me try different version of esp core

<!-- gh-comment-id:418379277 --> @tablatronix commented on GitHub (Sep 4, 2018): ``` *WM: [1] AutoConnect *WM: [1] AutoConnect: ESP Already Connected *WM: [2] Custom STA IP/GW/Subnet/DNS *WM: [1] STA IP set: 172.25.10.14 *WM: [1] AutoConnect: SUCCESS *WM: [1] STA IP Address: 172.25.10.14 Connected to local WiFI IP address: 172.25.10.14 MDNS responder started *WM: [1] AutoConnect *WM: [2] Connecting as wifi client... *WM: [2] Custom STA IP/GW/Subnet/DNS *WM: [1] STA IP set: 172.25.10.14 *WM: [3] WIFI station disconnect *WM: [1] Connecting to saved AP: shawn *WM: [3] WiFi station enable *WM: [3] enableSTA PERSISTENT ON *WM: [1] connectTimeout not set, ESP waitForConnectResult... *WM: [2] Connection result: WL_CONNECTED *WM: [3] lastconxresult: WL_CONNECTED *WM: [1] AutoConnect: SUCCESS *WM: [1] STA IP Address: 172.25.10.14 Connected to local WiFI IP address: 172.25.10.14 MDNS responder started ets Jan 8 2013,rst cause:2, boot mode:(3,6) load 0x4010f000, len 1384, room 16 tail 8 chksum 0x2d csum 0x2d v4ceabea9 ~ld *WM: [1] AutoConnect *WM: [2] Connecting as wifi client... *WM: [2] Custom STA IP/GW/Subnet/DNS *WM: [1] STA IP set: 172.25.10.14 *WM: [3] WIFI station disconnect *WM: [1] Connecting to saved AP: shawn *WM: [3] WiFi station enable *WM: [3] enableSTA PERSISTENT ON *WM: [1] connectTimeout not set, ESP waitForConnectResult... *WM: [2] Connection result: WL_CONNECTED *WM: [3] lastconxresult: WL_CONNECTED *WM: [1] AutoConnect: SUCCESS *WM: [1] STA IP Address: 172.25.10.14 Connected to local WiFI IP address: 172.25.10.14 MDNS responder started ``` This is what I get, looks ok to me. Let me try different version of esp core
Author
Owner

@bkrajendra commented on GitHub (Sep 5, 2018):

have u tried two methods?
One by doing hardware reset and
other by doing ESP.restart()
?
Because I got it every time i do it. its not even random.
Also one other thing is that why it shows default AP during regular working.
It always shows ESP_XXXX Ap after configuration complete and when connect after next restart
all time you will see this AP.

<!-- gh-comment-id:418800801 --> @bkrajendra commented on GitHub (Sep 5, 2018): have u tried two methods? One by doing hardware reset and other by doing ESP.restart() ? Because I got it every time i do it. its not even random. Also one other thing is that why it shows default AP during regular working. It always shows ESP_XXXX Ap after configuration complete and when connect after next restart all time you will see this AP.
Author
Owner

@tablatronix commented on GitHub (Sep 5, 2018):

I used the same sketch and added a start delay and a reset

<!-- gh-comment-id:418818788 --> @tablatronix commented on GitHub (Sep 5, 2018): I used the same sketch and added a start delay and a reset
Author
Owner

@tablatronix commented on GitHub (Sep 5, 2018):

ESP stores mode on its own, and that is the default. You should set whatever mode you want in your sketch , WM will not do this for you, or change it. I am thinking that this is somehow starting differently and WM is not able to correct it,

Do you have logging with esp wifi debugging on ?

Try setting mode sta before wm also

<!-- gh-comment-id:418827271 --> @tablatronix commented on GitHub (Sep 5, 2018): ESP stores mode on its own, and that is the default. You should set whatever mode you want in your sketch , WM will not do this for you, or change it. I am thinking that this is somehow starting differently and WM is not able to correct it, Do you have logging with esp wifi debugging on ? Try setting mode sta before wm also
Author
Owner

@bkrajendra commented on GitHub (Sep 5, 2018):

Im not getting what are you saying. I thought WM handles modes. and That's why we get initially it in AP mode and then in STA mode. The issue latter it should be only in STA mode. But I still see a AP.
image

See this WM code..

<!-- gh-comment-id:418832912 --> @bkrajendra commented on GitHub (Sep 5, 2018): Im not getting what are you saying. I thought WM handles modes. and That's why we get initially it in AP mode and then in STA mode. The issue latter it should be only in STA mode. But I still see a AP. ![image](https://user-images.githubusercontent.com/994083/45113258-7fe10000-b167-11e8-9c57-6111b61a7dea.png) See this WM code..
Author
Owner

@tablatronix commented on GitHub (Sep 5, 2018):

wm disables persistent when switching modes, leaving the default saved mode unaffected

<!-- gh-comment-id:418834044 --> @tablatronix commented on GitHub (Sep 5, 2018): wm disables persistent when switching modes, leaving the default saved mode unaffected
Author
Owner

@tablatronix commented on GitHub (Sep 5, 2018):

make sure you have the latest commits

<!-- gh-comment-id:418839555 --> @tablatronix commented on GitHub (Sep 5, 2018): make sure you have the latest commits
Author
Owner

@bkrajendra commented on GitHub (Jul 18, 2019):

Setting WiFi mode to WiFi.mode(WIFI_STA) in setup() resolves this issue.
This is only mentioned in one of the examples. It should be strictly mentioned somewhere in documentation.
else all ESP are left with open AP without any knowledge.
image

<!-- gh-comment-id:512932324 --> @bkrajendra commented on GitHub (Jul 18, 2019): Setting WiFi mode to WiFi.mode(WIFI_STA) in setup() resolves this issue. This is only mentioned in one of the examples. It should be strictly mentioned somewhere in documentation. else all ESP are left with open AP without any knowledge. ![image](https://user-images.githubusercontent.com/994083/61482295-e3f36800-a9b7-11e9-81bb-4b791c47570b.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#601
No description provided.