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

No WiFi connect since 2.3.0 if delay >= 1000 in setup() for init of external hardware #2702

Closed
heiko-wolf opened this issue Nov 21, 2016 · 5 comments

Comments

@heiko-wolf
Copy link

Hardware

Hardware: ESP-12
Core Version: 2.3.0

Description

No WiFi connect since 2.3.0 if "delay >= 1000" in setup() for init of external hardware.
After upgrading to 2.3.0 many sketches wont connect anymore to WiFi Accesspoint.
Testing a few things showed up that the problem was caused by adding a delay(1000) in setup before WiFi.begin().
This was done to power up external hardware properly before starting the Arduino/ESP Code and connecting the WiFi.
After downgrading to 2.2.0 everything works fine again using this delay.

Settings in IDE

Module: Wemos D1 R2 & mini
Flash Size: 4MB/3MB
CPU Frequency: 80Mhz

Sketch

#include <ESP8266WiFi.h>
char ssid[50] = "your ssid";
char password[50] = "your pwd";

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

delay(1000); // for ext. hardware init <<<<<<<<<<<

Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

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

void loop() {
delay(1000);
Serial.println("X");
}

@kendo55
Copy link

kendo55 commented Nov 30, 2016

i had that problem too !!! The Problem is not the delay().....

FIX FOR USING 2.3.0 CORE (only .begin if not connected)!!!!!!!

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
}
while (WiFi.status() != WL_CONNECTED) {
    delay(500);
Serial.print(".");
}

see:
(#2186)
and:
(#2594)

@heiko-wolf
Copy link
Author

Hi there,
youre right, after adding a WiFi.mode(WIFI_OFF) at the beginning of setup() and enable it just directly before WiFi.begin() after all other stuff is done and a few delays later averything works fine again :)
Thanks for pointing to the other issues !!

@cimba007
Copy link

cimba007 commented Jan 29, 2017

Got the same problem but none of the workarounds seems to fix it.
I do quite some heavy init stuff (> 1sec) and put WiFi.mode(WIFI_OFF); at the beginning of setup.

After my >1sec seconds I do this

WiFi.mode(WIFI_STA); listNetworks(0); 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 }
Still sometimes I got no networks found and after that no connection ..
....wifi evt: 1 STA disconnect: 201 ....wifi evt: 1 STA disconnect: 201 .....wifi evt: 1 STA disconnect: 201

After a clean power cycle the whole thing is working, just after flashing or sometimes on power-cycling from battery it is not working.

@mlord
Copy link

mlord commented Feb 27, 2017

Try using static IP rather than DHCP -- fixes it for me here. The internal DHCP seems to have issues under some conditions.

@johnwa27
Copy link

johnwa27 commented May 4, 2017

I just discovered this wonderful feature 😡. The workaround suggested in kendo55's post begs the question, "why is the module connected prior to WiFi.begin?". The workaround could be problematic if there is more than 1 AP and you need to connect to one specific one or change from one to the other.
I added a WiFi.disconnect() before WiFi.begin(). So far it has worked and I think it is a more robust solution.

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

No branches or pull requests

5 participants