No WiFi connection after upload - odd workaround needed
Posted: Wed Oct 16, 2019 10:09 am
I got an ESP-WROOM32 dev kit running well with a somewhat complex sketch, and then put it aside for some months. Now after purchasing an ESP-WROVER-KIT_V4.1 I compared the two and now found strange behaviour in both of them: after uploading a sketch, both failed to connect to WiFi, waiting in a WiFi.status() loop endlessly. But after pressing the Reset button, both would connect to WiFi almost instantaneously. So, my code seems ok.
I managed to reduce the code down to the minimum to demonstrate this effect with the WROVER. It has no connection of anything to any of its IO pins, and no SD-card inserted - it is as naked as possible:
Note the three lines commented with 1st, 2nd, and 3rd! When 2nd and 3rd were commented out, this is the result in the Serial Monitor after upload:
It looks like the WiFi code is giving up too quickly? Obviously, something has changed during the time I didn't touch my old ESP. Was it some (Arduino) code? or was it my router, a Fritz!Box 7490 (it may have received an upgrade during that time, but I am not sure).
I managed to reduce the code down to the minimum to demonstrate this effect with the WROVER. It has no connection of anything to any of its IO pins, and no SD-card inserted - it is as naked as possible:
Code: Select all
// Wifi connection problems
#include <WiFi.h>
const char* ssid = "mySSID";
const char* password = "myPW";
void setup() {
Serial.begin(115200);
Serial.println("\nConnecting to WIFI");
WiFi.begin(ssid, password); // 1st
delay(10); // 2nd # 5ms: not ok, 8ms: often ok, 10ms: ok
WiFi.begin(ssid, password); // 3rd
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(200);
}
long rssi = WiFi.RSSI(); // RSSI (Received Signal Strength in dBm)
Serial.printf("Successfully connected, getting RSSI: %li \n", rssi);
}
void loop() {
Serial.print("Looping ");
delay(2000);
}
There is no end to the dots (indicating a wait for connection). The very same results come when I comment out only line 2nd, i.e. I have two subsequent WiFi.begin() commands. But when I un-comment 2nd, and thereby have a delay of 10ms between the two WiFi.begin() commands, it works all the time, like this:Connecting to WIFI
...................................................................................
In fact, it still works most of the time with an 8ms delay, but it does not work with only a 5ms delay.Connecting to WIFI
.Successfully connected, getting RSSI: -26
Looping Looping Looping Looping Looping Loo
It looks like the WiFi code is giving up too quickly? Obviously, something has changed during the time I didn't touch my old ESP. Was it some (Arduino) code? or was it my router, a Fritz!Box 7490 (it may have received an upgrade during that time, but I am not sure).