Page 1 of 1

Problems connecting to WIFI

Posted: Sun Apr 11, 2021 6:39 pm
by s710__
I have a sparkfun thing esp32, and I want it to connect to my wifi. Its a 2.4GHz wifi with WPA. I am using the following code:

Code: Select all

#include <WiFi.h>

WiFiClient wifiClient;  // needed later for MQTT
  
void connectWIFI()
{
  Serial.printf("[WIFI] Connecting to network %s ...\n", WIFI_SSID);

  WiFi.begin(WIFI_SSID, WIFI_PASS);

  while (WiFi.status() != WL_CONNECTED) 
  {
    Serial.printf("WIFI Status: %d\n", WiFi.status());
    Serial.print(".");
    WiFi.begin(WIFI_SSID, WIFI_PASS);
    delay(1000);
  }

  Serial.println(" connected");
}
Which is basically the example you get all over the internet when googling for how to connect to WIFI.
Since it didnt work out of the box, I have added a line printing the WIFI status, which always prints 6. I was lucky exactly 1 time out of maybe 20 resets, where it actually connected to the wifi.

I have googled for the issue, unable to find a working solution. I have also tried to erase the flash using the esptool (`esptool --port /dev/cu.usbserial-D309CAHZ erase_flash`), which did not improve the situation.

Can someone help me out?

Also:
I found tons of examples on the internet showing how to connect to WIFI, however there seems to be 2 general types of examples:
- only call WiFi.begin() once
- call WiFi.begin() in the wait loop

Which one is correct?

[edit] Wanted to mention I am using this URL in arduino settings:
https://raw.githubusercontent.com/espre ... index.json

And I have installed esp32 v1.0.6 in the board manager.

Re: Problems connecting to WIFI

Posted: Tue Apr 13, 2021 12:11 pm
by s710__
I have tried a ton of times now, and what I get the feeling of is the following:
1) after changing code and uploading, it works exactly ONCE to instantly connect to the wifi
2) since I have a 15s loop of connect/disconnect in my loop(), this also means that after 1) above (still the same boot) it does not work anymore
3) it does not matter what the delay() in the connect-loop is
4) i have tried `WiFi.mode(WIFI_STA);`, I have tried `WiFi.reconnect()` in the loop, I have tried `WiFi.setSleep(false);` all without effe t

With "not work anymore" to connect I mean: The connect-loop runs for several minutes, until it eventually succeeds to connect, after maybe 3 minutes.

When I unplug the ESP32, and connect it again, after a fresh boot it will work around 5 times in a row until it falls again into the non-working state.

All in all, everything seems to be working rather non-deterministic and unreliable. I have downgraded to esp32 v1.0.5 because of https://github.com/espressif/arduino-esp32/issues/4980, however with no success.