Problems connecting to WIFI
Posted: Sun Apr 11, 2021 6:39 pm
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:
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.
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");
}
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.