esp8266 / Arduino

ESP8266 core for Arduino
GNU Lesser General Public License v2.1
16.03k stars 13.33k forks source link

WiFi cannot connect until a power cycle. #5527

Closed Swedish-Coder closed 4 years ago

Swedish-Coder commented 5 years ago

Basic Infos

Platform

-Hardware: ESP8266 -Core Version: 2.4.2 -Development Env: Visual Micro -Operating System: Windows

Settings in IDE

-Module: Generic ESP8266 Module -Flash Mode: qio -Flash Size: 2MB (256k Spiffs) -lwip Variant: v1.4 -Reset Method: ck -Flash Frequency: 40Mhz -CPU Frequency: 80Mhz -Upload Using: Serial -Upload Speed: 921600

Problem Description

Using the reconnect from below works fine 99% of the time. Running this test on ~50 ESP8266. Reconnect is called every 30seconds. After some undefined time (ranging from 1h to 10days..) the Wifi will not be able to reconnect.

The Status stays like this until the device is reset (hardware reboot), have tried letting the devices stay in this mode for days, but they never recover. Rebooting the AP does not help. The signal strength is also not the issue (ran a test with AP in front of ~42 ESP8266 with ~2m away from devices, they all had ~ -65 dba).

Have tried different disconnect / reconnects, all resulting in the same stale state. Currently trying WiFi.disconnect(true); forceSleepBegin(35000); //…do other tasks for 25ms WiFi.forceSleepWake(); WiFi.persistent(false); WiFi.begin(ssid.c_str(), psk.c_str());

This sometimes causes crashes on the WiFi.begin(..) line.

Is there a way to “properly” do a reconnect on WiFi, or a way to reset the WiFi to “hardware boot” status (delete all DHCP information, known AP, etc.)?

MCVE Sketch

void Reconnect(){
WiFi.disconnect(true);
WiFi.mode(WIFI_STA);

While(WiFi.status() != WL_CONNECTED){
//do other things
}
Serial.println(String(F("[WiFi] Connect now... heap: ")) + String(ESP.getFreeHeap()) + String(F(", ts: ")) + String(millis()));

//… load ssid & pass from spiffs
WiFi.begin(ssid.c_str(), psk.c_str());
}
TD-er commented 5 years ago

I'm not entirely sure if it is still relevant. These "cannot reconnect" issues often just happened after a long time, which makes it really hard to reproduce.

I have now 2 nodes running with the patch you mentioned (previous version of it). For example:

Unit Number: 75
Local Time: 2019-09-12 00:08:06
Uptime: 2 days 12 hours 19 minutes
Connected: 8h06m
Last Disconnect Reason: (201) No AP found
Number Reconnects: 7

So it seems it was very well capable of reconnecting (some of these reconnects were me kicking the node from the AP, only during the first hour after boot) But that's just too few nodes to tell if it is now fixed.

devyte commented 4 years ago

The pseudo modes are merged. The original issue reported y @Swedish-Coder is old. A whole lot has changed since it was reported, including several relevant fixes. Closing. If you think the problem is still relevant, please open a new issue and follow the template instructions.