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

WiFi.begin doesn't connect if connection was already established #2186

Closed
RogerSchaefer opened this Issue Jun 24, 2016 · 42 comments

Comments

Projects
None yet
@RogerSchaefer
Copy link

RogerSchaefer commented Jun 24, 2016

Installed the new 2.3.0 today and found that a sketch I have used for a long time will no longer cause the ESP8266 to connect with my WiFi

I reverted to version 2.2.0 and the sketch works fine.

ESP8266WiFi was the only ESP8266 include in the sketch

Roger

@igrr

This comment has been minimized.

Copy link
Member

igrr commented Jun 24, 2016

Will you post your sketch? I can try reproducing that issue.

@hoshinota

This comment has been minimized.

Copy link

hoshinota commented Jun 24, 2016

"Millis ()" is strange?
Value of ADC was also been 20 - 30 points lower.

@RogerSchaefer

This comment has been minimized.

Copy link

RogerSchaefer commented Jun 24, 2016

Hi igrr,
The code is below; hope it helps.
Roger
///////////////////////////////////////////
// my dashboard
// https://io.adafruit.com/Oldmicroguy/
//
/***************************************************
Adafruit MQTT Library ESP8266 Example

Must use ESP8266 Arduino from:
https://github.com/esp8266/Arduino

Works great with Adafruit's Huzzah ESP board & Feather
----> https://www.adafruit.com/product/2471
----> https://www.adafruit.com/products/2821

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Tony DiCola for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
////////////////////////////
// pick one test device //
// //
#define ECOSWITCH 0 //
#define SWEETPEA 0 //
#define NODEMCU 0 //
#define ESP01 1 //
#define THING 0 // Sparkfun Thing
#define SONOFF 0 //
////////////////////////////

#if ESP01 // testing with ESP-01
#define BUTTON_PIN 0
#define LED_PIN 2
#define RELAY 2 // only two outputs on ESP-01
#define INVERT false
#endif

#if THING // testing with Sparkfun THING
#define BUTTON_PIN 0
#define LED_PIN 5
#define RELAY 12
#define INVERT false
#endif

#if SWEETPEA // testing with SweetPea
#define BUTTON_PIN 0
#define LED_PIN BUILTIN_LED
#define RELAY BUILTIN_LED
#define INVERT false
#endif

#if SONOFF // WiFi controlled power relay
#define BUTTON_PIN 0
#define LED_PIN 13
#define RELAY 12
#endif

//#define PULLUP true
//#define INVERT true
//#define DEBOUNCE_MS 100
//#define SINK false

/************************* WiFi Access Point *********************************/

#define WLAN_SSID "T-Mobile Broadband96"
#define WLAN_PASS "xxxxxxx"

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER "io.adafruit.com"
#define AIO_SERVERPORT 1883 // use 8883 for SSL
#define AIO_USERNAME "Oldmicroguy"
#define AIO_KEY "xxxxxxxxxx"

/************ Global State (you don't need to change this!) ******************/

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;
// or... use WiFiFlientSecure for SSL
//WiFiClientSecure client;

// Store the MQTT server, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);

/****************************** Feeds ***************************************/

// Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: /feeds/

const char PHOTOCELL_FEED[] PROGMEM = AIO_USERNAME "/feeds/photocell";
Adafruit_MQTT_Subscribe photocell = Adafruit_MQTT_Subscribe(&mqtt, PHOTOCELL_FEED);

// Setup a feed called 'onoff' for subscribing to changes.
const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoffbutton";
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);

/*************************** Sketch Code ************************************/

// Bug workaround for Arduino 1.6.6, it seems to need a function declaration
// for some reason (only affects ESP8266, likely an arduino-builder bug).
//void MQTT_connect();

void setup() {
Serial.begin(9600);
delay(10);
pinMode(LED_PIN, OUTPUT); // Initialize the BUILTIN_LED pin as an output
pinMode(RELAY,OUTPUT);
digitalWrite(RELAY, LOW);
blink(5);
digitalWrite(LED_PIN, LOW);
Serial.println();
Serial.println(F("Adafruit MQTT demo"));

// Connect to WiFi access point.
Serial.println(); Serial.println();
Serial.print("Connecting to ");
Serial.println(WLAN_SSID);

WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();

Serial.println("WiFi connected");
Serial.println("IP address: "); Serial.println(WiFi.localIP());

// Setup MQTT subscription for onoff feed.
mqtt.subscribe(&onoffbutton);
mqtt.subscribe(&photocell);
}
////////// End of Setup ///////////////////
///////////////////////////////////////////
uint32_t x=0;

void loop() {
// Ensure the connection to the MQTT server is alive (this will make the first
// connection and automatically reconnect when disconnected). See the MQTT_connect
// function definition further below.
MQTT_connect();

// this is our 'wait for incoming subscription packets' busy subloop
// try to spend your time here

Adafruit_MQTT_Subscribe *subscription;
while ((subscription = mqtt.readSubscription(1000))) {
// Check if its the onoff button feed
if (subscription == &onoffbutton) {
Serial.print(F("On-Off button: "));
Serial.println((char *)onoffbutton.lastread);

  if (strcmp((char *)onoffbutton.lastread, "ON") == 0) {
    digitalWrite(LED_PIN, LOW); 
  }
  if (strcmp((char *)onoffbutton.lastread, "OFF") == 0) {
    digitalWrite(LED_PIN, HIGH); 
  }
}
if (subscription == &photocell) {
  //Serial.print(F("Value "));
  //Serial.println((char *)photocell.lastread);
  Serial.print(F("Temperature "));
  float temp = atof((char *)photocell.lastread);
  Serial.print(temp, 1);
  Serial.println(" F");
  if (temp < 69.0) {
    if (INVERT) digitalWrite(LED_PIN, HIGH); else digitalWrite(LED_PIN,LOW);
    if (INVERT) digitalWrite(RELAY, HIGH); else digitalWrite(RELAY, LOW);
  }
  if (temp > 70.0) {
    if (INVERT) digitalWrite(LED_PIN, LOW); else digitalWrite(LED_PIN,HIGH);
    if (INVERT) digitalWrite(RELAY, LOW); else digitalWrite(RELAY, HIGH);
  }
}

}
// Now we can publish stuff!
/*
Serial.print(F("\nSending photocell val "));
Serial.print(x);
Serial.print("...");
if (! photocell.publish(x++)) {
Serial.println(F("Failed"));
} else {
Serial.println(F("OK!"));
}*/
// ping the server to keep the mqtt connection alive
// NOT required if you are publishing once every KEEPALIVE seconds

if(! mqtt.ping()) {
mqtt.disconnect();
}
}
//////// End of Loop //////////////////
//////////////////////////////////////

// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
int8_t ret;

// Stop if already connected.
if (mqtt.connected()) {
return;
}

Serial.print("Connecting to MQTT... ");

uint8_t retries = 3;
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Serial.println(mqtt.connectErrorString(ret));
Serial.println("Retrying MQTT connection in 5 seconds...");
mqtt.disconnect();
delay(5000); // wait 5 seconds
retries--;
if (retries == 0) {
// basically die and wait for WDT to reset me
while (1);
}
}
Serial.println("MQTT Connected!");
}
///////////////////////////////
void blink (int i) {
while (i) {
digitalWrite(LED_PIN, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on)
delay(250); // Wait a bit
digitalWrite(LED_PIN, HIGH); // Turn the LED off by making the voltage HIGH
delay(250);
i--;
}
}
///////////////////////////////

@zfields

This comment has been minimized.

Copy link

zfields commented Jun 24, 2016

I am using the AzureIoTHub simplesample_http. It works perfectly with 2.2, but upon grading to 2.3 I get this experience. I can connect to my router (reports assigned an IP address), but it keeps looping as though it failed and spews cryptic debugging errors.

@mkeyno

This comment has been minimized.

Copy link

mkeyno commented Jun 25, 2016

I have same problem with it , my connection get lost sometimes but module try to reconnect to Access point , and this make me problem when using the websocket

@igrr

This comment has been minimized.

Copy link
Member

igrr commented Jun 25, 2016

@RogerSchaefer
I have loaded the provided sketch, changed SSID and password and connection went fine.
Could you please provide serial output when debugging is enabled?
Please set "Debug Port: Serial" and "Debug Level: Core" in Arduino Tools menu, and add Serial.setDebugOutput(true); line after Serial.begin(9600);. This will print some info from WiFi stack.
We had an SDK update between 2.2.0 and 2.3.0. Because SDK updates sometimes don't migrate parameter storage area in flash correctly, this can cause connection issues. Debug output can give more hints at what's happening on your side.

@zfields since this is a third party library, best we can do is help you make sense of "cryptic debugging errors" (whatever that may mean). Please feel free to open an issue, and provide the exact sketch you are running, settings you have in IDE tools menu, and full serial output. Thanks.

@RogerSchaefer

This comment has been minimized.

Copy link

RogerSchaefer commented Jun 25, 2016

Hello @igrr
I have attached debug files from both Ver 2.2.0 and Ver 2.3.0
The object of the sketch is to get mqtt temperature data.
Ver 2.2.0 connects quickly
Ver 2.3.0 sometimes after 10 or 20 minutes

Roger

sonoff_mqtt Ver 2.3.0.txt
sonoff_mqtt Ver 2.2.0.txt

@igrr

This comment has been minimized.

Copy link
Member

igrr commented Jun 26, 2016

Thanks for the logs, I was able to reproduce this with 2.3.0.

Apparently, with SDK 1.5.3, if you call WiFi.begin by the time WiFi connection is already established, WiFi connection state machine enters some weird state. SDK function wifi_station_get_connect_status keeps returning STATION_CONNECTING, even though the connection is in fact established.

This was resolved in SDK 1.5.4, which is available in current git version of ESP8266 core.
I tested the same code with git version and it worked fine.

As a workaround, you can replace WiFi.begin(ssid, password); with

if (WiFi.status() != WL_CONNECTED) {
  WiFi.begin(ssid, password);
}

or with

WiFi.persistent(false);
WiFi.mode(WIFI_OFF);   // this is a temporary line, to be removed after SDK update to 1.5.4
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);

I will consider releasing 2.3.1 with a workaround for this issue in a couple of days.

@igrr igrr changed the title ESP8266WiFi doesn't work with new 2.3.0 WiFi.begin doesn't connect if connection was already established Jun 26, 2016

@SupotSaeEa

This comment has been minimized.

Copy link

SupotSaeEa commented Jul 2, 2016

I fact the same problem.
Test on Generic ESP-01
Debug show something like not found my router (belkin.a57).
Connect wifi with ESP8266WiFiMulti library.

But work fine on NodeMCU1.0 (ESP-12E Module)

***** Resullt on ESP-01
Begin...
del if0
usl
mode : null
mode : sta(18:fe:34:98:6a:e2)
add if0
f r0, scandone
f r0, scandone
state: 0 -> 2 (b0)
state: 2 -> 0 (2)
reconnect
f 0, scandone
state: 0 -> 2 (b0)
state: 2 -> 0 (2)
reconnect
f -180, scandone
no belkin.a57 found, reconnect after 1s
f r0, scandone
f r0, scandone
state: 0 -> 2 (b0)
state: 2 -> 0 (2)
reconnect
f 0, scandone
state: 0 -> 2 (b0)
state: 2 -> 0 (2)
reconnect
f -180, scandone
no belkin.a57 found, reconnect after 1s

//
***** Below is result on NodeMCU1.0 (ESP-12E Module)
Begin...
scandone
f r0, scandone
f r0, scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 7
cnt

connected with belkin.a57, channel 6
dhcp client start...
ip:192.168.1.11,mask:255.255.255.0,gw:192.168.1.1
please start sntp first !
[8][192.168.1.11] GET payload: {"D1":"ON","SW1":""OFF""} D1 = ON

@igrr

This comment has been minimized.

Copy link
Member

igrr commented Jul 4, 2016

@SupotSaeEa doesn't look like the same issue to me, because there are reconnect attempts visible in the log. Please check that you are setting correct flash size when compiling for you ESP-01 module. Usually they have smaller flash size than NodeMCU (512k or 1M).

@SupotSaeEa

This comment has been minimized.

Copy link

SupotSaeEa commented Jul 5, 2016

@igrr I add WiFi.setOutputPower(0); ESP-01 is work on 2.3.0.

@MPX4132

This comment has been minimized.

Copy link

MPX4132 commented Jul 20, 2016

@SupotSaeEa's workaround seems to fix the issue for the ESP03 as well.

WiFi.setOutputPower(0);
WiFi.begin(ssid, password);

I can also confirm the settings are correctly set on the IDE for the module, checked every time I compiled. I tried checking with the older versions (2.0.0 - 2.2.0) but apparently I can't compile with them. Keeps throwing the following:

Uploading 227872 bytes from to flash at 0x00000000
error: failed reading byte
warning: espcomm_send_command: cant receive slip payload data
warning: espcomm_send_command(FLASH_DOWNLOAD_BEGIN) failed
error: espcomm_upload_mem failed

I'd like to reiterate that it works perfectly fine with the 2.3.0 package, just needs the workaround mentioned.

@PavelDorofeev

This comment has been minimized.

Copy link

PavelDorofeev commented Sep 1, 2016

I have the same problem on ESP-12 Lolin (Arduino 1.6.8). Reset ESP-12 , WiFI.begin() and WiFi.status() != WL_CONNECTED waits forever. Only repower the WIFI router help me.

This solves the problem fine.

WiFi.persistent(false);
WiFi.mode(WIFI_OFF);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);

Thanks iggr.

@CapnNemo

This comment has been minimized.

Copy link

CapnNemo commented Oct 8, 2016

This may or may not be the same bug, but I'm using the Arduino IDE, and an Adafruit Huzzah, and the sketch I have works fine (Wifi.begin works fine and connects), until I upgrade the board from 2.1.0 to either 2.2.0 or 2.3.0 - in both cases, it no longer connects.

Also, neither of the two fixes (output power to zero, nor mode to WIFI_OFF) as shown above works (but maybe they only work when using lua?).

I haven't used the lua system, so for the moment this is only so helpful, but wanted to see if this sounds like the same bug, or a different bug, before I get too far.

Thanks!

@SupotSaeEa

This comment has been minimized.

Copy link

SupotSaeEa commented Oct 8, 2016

I still confirm on solution to set output power to zero. Especially on
ESP-01.

Supot Sae-Ea
สุพจน์ แซ่เอีย
081-454-0853

2016-10-08 8:54 GMT+07:00 CapnNemo notifications@github.com:

This may or may not be the same bug, but I'm using the Arduino IDE, and an
Adafruit Huzzah, and the sketch I have works fine (Wifi.begin works fine
and connects), until I upgrade the board from 2.1.0 to either 2.2.0 or
2.3.0 - in both cases, it no longer connects.

Also, neither of the two fixes (output power to zero, nor mode to
WIFI_OFF) as shown above works (but maybe they only work when using lua?).

I haven't used the lua system, so for the moment this is only so helpful,
but wanted to see if this sounds like the same bug, or a different bug,
before I get too far.

Thanks!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#2186 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AED2PWyrQQ5sxg8UkNgsIn3WjSPRuJ_Iks5qxve_gaJpZM4I9d2q
.

@19eighties

This comment has been minimized.

Copy link

19eighties commented Oct 11, 2016

Just to chime in with my own observations... I have been getting this bug also. Sometimes it is random, but happens the first time I try connecting a new ESP module 100% of the time with my sketch. If I upload the wificlientbasic sketch and it connects I can then upload my own sketch and it can then connect to my AP. I also find I cannot connect if I had just previously put the ESP module into AP mode. So then I have to do the "reset" as I just described.

Edit: tried the suggestions above and did not work:

WiFi.persistent(false);
WiFi.mode(WIFI_OFF); 
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);

Debug spits out chg_A2:-40 during attempts to connect.

@kendo55

This comment has been minimized.

Copy link

kendo55 commented Nov 13, 2016

i had that problem too !!!
i fixed it with:

if (WiFi.status() != WL_CONNECTED) {  // FIX FOR USING 2.3.0 CORE (only .begin if not connected)
    WiFi.begin(ssid, password);       // connect to the network
}    

for ( count = 0; count < 20 ; count++ )  {
      delay(500);
      wifi_stat = WiFi.status();  
      Serial.print( count ); Serial.print( " WifiStat: " );
      Serial.println( wifi_stat );
      if ( wifi_stat == WL_CONNECTED ) {
        break;
      }
}

Serial.println("");

if ( count < 20 ) {
    Serial.println("WiFi connected");
}else{
    Serial.println("Client !!!NOT!!! connected");

   // create a SoftAP for access
   WiFi.softAP(ESPssid, ESPpassword);
   // etc..........
}
@borch84

This comment has been minimized.

Copy link

borch84 commented Dec 19, 2017

Hello, I am having the same issue. Adafruit feather huzzah ESP8266 is not connecting to wifi. It used to connect but now it is stuck at the connecting step.

The code that I am using now is 2.1.0, however I've tried with 2.2 and 2.3.

This is the code I am using:

void setup() {

//start the serial line for debugging
Serial.begin(9600);
Serial.setDebugOutput(true);

//start wifi subsystem
WiFi.disconnect();
WiFi.persistent(false);
WiFi.mode(WIFI_OFF);
WiFi.mode(WIFI_STA);
WiFi.setOutputPower(0);
//WiFi.begin(ssid, password);
//WiFi.config(ip,gateway,subnet);
//attempt to connect to the WIFI network and then connect to the MQTT server
reconnect();
//wait a bit before starting the main loop
//delay(2000);
}

void reconnect() {

//attempt to connect to the wifi if connection is lost
if(WiFi.status() != WL_CONNECTED){
//debug printing
Serial.print("Connecting to ");
Serial.println(ssid);

//loop while we wait for connection
while (WiFi.status() != WL_CONNECTED) {
  WiFi.begin(ssid, password);
  Serial.print(".");
  delay(500);    
}

//print out some more debug once connected
Serial.println("");
Serial.println("WiFi connected");  
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

}
}

From the serial monitor I can see these messages:

f r0, ..0�~?�4�!��{��OAa�bcn 0
del if1
del if0
usl
mode : null
mode : sta(5c:cf:7f:00:6b:cc)
add if0
Connecting to Apartamentos villa
f r0, .....scandone
no Apartamentos villa found, reconnect after 1s
reconnect
f 0, ....scandone
no Apartamentos villa found, reconnect after 1s
reconnect
f -180, .....scandone

I've been thinking to reflash the ESP.

Any suggestions?

Thank you.

@martin072

This comment has been minimized.

Copy link

martin072 commented Dec 24, 2017

Hi all,

Is there any update on this issue? I am experiencing the same problems... the wemos doesn't seem to connect to the WiFi. This is my debug output:

Connecting to: FlyingDutchmen
del if0
usl
mode : null
mode : sta(60:01:94:33:00:c0)
add if0
...scandone
state: 0 -> 2 (b0)
..state: 2 -> 0 (2)
reconnect
...scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 1
cnt
......state: 5 -> 2 (2a0)
rm 0
.reconnect
state: 2 -> 0 (0)
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 1
cnt
......state: 5 -> 2 (2a0)
rm 0
..reconnect
state: 2 -> 0 (0)
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 1
cnt
.....state: 5 -> 2 (2a0)

@igrr igrr closed this Jan 2, 2018

@igrr igrr removed the staged-for-release label Jan 2, 2018

@TobiNorris

This comment has been minimized.

Copy link

TobiNorris commented Jan 5, 2018

I had the same problem...It works fine to me:

WiFi.mode(WIFI_OFF); //workaround
WiFi.mode(WIFI_AP_STA);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

@seblanc

This comment has been minimized.

Copy link

seblanc commented Feb 21, 2018

If you don't want to loose connection of the ESP8266 AP, you can use:

WiFi.mode(WIFI_AP); // workaround
WiFi.mode(WIFI_AP_STA);
WiFi.begin(ssid, password);

Works with NodeMCU 1.0 and esp8266 v2.4

@NeilRShah

This comment has been minimized.

Copy link

NeilRShah commented Mar 6, 2018

I will confirm that the bug exists for me as well on a NodeMCU 1.0, using the Arduino IDE with the esp8266 board library installed.

I used this workaround suggested by @igrr and it is working now:

WiFi.persistent(false);
WiFi.mode(WIFI_OFF);   // this is a temporary line, to be removed after SDK update to 1.5.4
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
@borqborq

This comment has been minimized.

Copy link

borqborq commented Apr 30, 2018

I've had the same intermittent problem with several NodeMCU v0.9 and v1.0 units. This code fixed it for me. Thanks to all that contribute!

#include <ESP8266WiFi.h>

const char* ssid = "YOUR-SSID";
const char* password = "YOUR-SSID-PASS";

void setup (){
  Serial.begin(115200);

  delay(3000);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  Serial.println(password);

// ---------------This was the magic WiFi reconnect fix for me
  WiFi.persistent(false);
  WiFi.mode(WIFI_OFF);   // this is a temporary line, to be removed after SDK update to 1.5.4
  WiFi.mode(WIFI_STA);  
// ---------------END - WiFi reconnect fix

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  
  Serial.println("WiFi connected");
  Serial.println(WiFi.localIP());
}

void loop() {
  
  }
@luffykesh

This comment has been minimized.

Copy link

luffykesh commented Jun 7, 2018

I had a issue where, when ESP is assigned static IP from the router, it would connect to AP but fail to obtain IP.
Router: Dlink DIR-600M
Arduino Firmware: 2.4.1

The issue was persistent in lwIP v2.0 Higher Bandwidth and Low Memory.
Changing lwIP variant to "v1.4 Higher Bandwidth" solves the issue, does not matter if you WiFi.persistent(false);

@d-a-v

This comment has been minimized.

Copy link
Collaborator

d-a-v commented Jun 7, 2018

@luffykesh This is a bug in 2.4.1 fixed in latest git version.

@luffykesh

This comment has been minimized.

Copy link

luffykesh commented Jun 7, 2018

@d-a-v Thank you.
The git version does fix the issue with lwIP v2 of not connecting, but the connection(DHCP) time sometimes is around 15-20 seconds or more, whereas lwIP v1.4 establishes connection in 8-10 seconds.
Again,
IP assigned static from router.

@d-a-v

This comment has been minimized.

Copy link
Collaborator

d-a-v commented Jun 7, 2018

IP assigned static from router.

Beeing more specific, in STA mode, getting address by DHCP server (no static IP address in the sketch), you are observing twice more delay with lwip-v2 than with lwip-v1.4 ?

@luffykesh

This comment has been minimized.

Copy link

luffykesh commented Jun 7, 2018

@d-a-v

you are observing twice more delay with lwip-v2 than with lwip-v1.4 ?

Yes.

@luffykesh

This comment has been minimized.

Copy link

luffykesh commented Jun 8, 2018

@d-a-v
I have again encountered the issue.
I have tried on both esp8266-12E and esp8266-12S with the git version, with lwIP v2, but cannot connect to the station.
lwIP v1.4 works with both git version and when installed from Arduino's board manager.

@d-a-v

This comment has been minimized.

Copy link
Collaborator

d-a-v commented Jun 12, 2018

@luffykesh
Regarding connection delay, I played with the interactive sketch that you can find in File>examples>esp8266> and I noticed no much difference between the two versions of lwIP.
Regarding the connection issue you have, we need you to open a new issue describing the most accurately possible, by filling the issue template, what you are facing.

@fabian727

This comment has been minimized.

Copy link

fabian727 commented Jun 24, 2018

Hi alltogether,
is there already an official bug fix? I encounter connection problems too.
I have the WEMOS D1 mini (with ESP8266MOD (so I think also called ESP12E))
and a WEMOS NodeMcu V3 of LoLin.
I am working on IDE 1.8.4 on Ubuntu 18.04

Both refuse to connect to my router. I already flashed them a while ago, but this won't work any more.
My test-sketch at the moment

#include <ESP8266WiFi.h>

void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  
  WiFi.mode(WIFI_OFF);
  delay(2000);
  WiFi.mode(WIFI_AP_STA);
  WiFi.hostname("DEBUG");
  while (WiFi.status() != WL_CONNECTED) {
    WiFi.begin("WLAN_SSID",WLAN_PWD");
    delay(5000);
    Serial.print(".");
  }

    Serial.println("");
    Serial.println("WiFi connected");
   
    // Print the IP address
    Serial.print("My IP: ");
    Serial.println(WiFi.localIP());

  delay(500);
}

void loop() {
  delay(5000);
}

I also tested some sketches from here and to setPowerOutput to 0. Nothing helped.

My DebugOutput:

done
state: 0 -> 2 (b0)
..state: 2 -> 0 (2)
reconnect
......scandone
state: 0 -> 2 (b0)
..state: 2 -> 0 (2)
reconnect
......scandone
state: 0 -> 2 (b0)
..state: 2 -> 0 (2)
reconnect
.....scandone
state: 0 -> 2 (b0)
. and so on

I changed between Wifi V1.4, V2 low mem and high band. Nothing...

Any further ideas?

Thanks,
Fabian

Update:
I can connect to my AP of my mobile phone. It has default only WPA2 or no pwd at all.
My router with configuration of 2.4 Ghz and WPA2 is not found. 2.4/5 Ghz; WPA2 is found, but won't connect

@CapnNemo

This comment has been minimized.

Copy link

CapnNemo commented Jun 24, 2018

@fabian727

This comment has been minimized.

Copy link

fabian727 commented Jun 25, 2018

the arbitrary time is between 0 and 0.1 ms I would say, or in other words: instantly.

I got it working: it seems the WiFi module does not support WPA. I changed my security from WPA & WPA2 to only WPA2. Now it works. I think there is a big bug in the lib

@mmaxus35

This comment has been minimized.

Copy link

mmaxus35 commented Jun 27, 2018

I am dealing with this issue right now and i have applied to code the given solutions.
wifi.persistent(false);
wifi.begin(WIFI_OFF);

So far, i tested my system under a 8W fan load, i made POST request instantly to cause the system drop from wifi because of high current consumption and it did. Then i coded esp to re-estabilish wifi connection . I tested the system for 50 times to drop it and re-estabilish, as result at the 51.th of the trial it did not re-estabilish the connection ( i have waited 15 min to be re-connected ) but it did not. So far this is the temporarly best solution. Moreoever, if there are permanent solution for this problem, could you share please ?

Thanks.

@d-a-v

This comment has been minimized.

Copy link
Collaborator

d-a-v commented Jun 27, 2018

@mmaxus35 Please try latest master. Yesterday's fixes were about WiFi disconnection and reconnection.

@mmaxus35

This comment has been minimized.

Copy link

mmaxus35 commented Jun 27, 2018

@d-a-v Okey ' i will thank a lot 👍

@d-a-v I tried the latest version on PlatformIO and tried wifi.reconnect() yet it did not re-connected :(

@fabian727

This comment has been minimized.

Copy link

fabian727 commented Jun 28, 2018

as already stated I changed from WPA & WPA2 to only WPA2. This module with this flashed code worked. Now nothing works. I had to shut off and on again my router and reconfigure many devices to work again... seems to be only a lucky solution

@TobiNorris

This comment has been minimized.

Copy link

TobiNorris commented Jun 28, 2018

@d-a-v , how can I use this source code to upload in my board? I got the master branch, but I don´t know how to upload this into my board.

@d-a-v

This comment has been minimized.

Copy link
Collaborator

d-a-v commented Jun 28, 2018

@mmaxus35 I don't know the status of PlatformIO. The fixes mentioned above are very recent and are for the arduino core with lwIP-v2.

@fabian27 please open a new issue and fill the issue template with all details you can.

@TobiNorris Using the git master branch (all documentation's steps must be followed) or downloading the arduino core through the board manager result in the same IDE and tools. Press the Arduino IDE upload button.

To all, this thread #2186 is an old issue, about an old version of the core, fixed, solved and closed. Your issues are unrelated with the OP. Please open new issues with your specific problems.

edit: Followup to: WiFi cannot connect until a power cycle. #5527

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment