Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP8266 static IP changes on reset. #719

Closed
4 of 10 tasks
bkrajendra opened this issue Sep 3, 2018 · 12 comments
Closed
4 of 10 tasks

ESP8266 static IP changes on reset. #719

bkrajendra opened this issue Sep 3, 2018 · 12 comments
Labels
bug Validated BUG
Milestone

Comments

@bkrajendra
Copy link

bkrajendra commented Sep 3, 2018

----------------------------- 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

@tablatronix
Copy link
Collaborator

erase flash ?

@tablatronix
Copy link
Collaborator

#720

@tablatronix tablatronix added the bug Validated BUG label Sep 3, 2018
@tablatronix tablatronix added this to the dev milestone Sep 3, 2018
@bkrajendra
Copy link
Author

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.

@bkrajendra
Copy link
Author

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

@tablatronix
Copy link
Collaborator

tablatronix commented 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

@bkrajendra
Copy link
Author

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.

@tablatronix
Copy link
Collaborator

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

@tablatronix
Copy link
Collaborator

tablatronix commented 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

@bkrajendra
Copy link
Author

bkrajendra commented 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..

@tablatronix
Copy link
Collaborator

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

@tablatronix
Copy link
Collaborator

make sure you have the latest commits

@bkrajendra
Copy link
Author

bkrajendra commented 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Validated BUG
Projects
None yet
Development

No branches or pull requests

2 participants