Hi all,
I'm new to programming on ESP32 and networking so please forgive the simple mistakes. I am trying to connect my board to my home wifi without success. I searched a number of other posts but can't seem to figure this one out.
I am able to get it to connect to my iphone hotspot and get an IP address, so that's a plus.
I can see my home network when i do a network scan.
When i attempt to connect, the return code is 6 for the first attempt or 2.. then after that it's 4.
The only thing i can think of is it doesn't like my wifi name.
Thanks in advance for any ideas or help.
The debug messages I get out are here:
13:07:24.638 -> 13 networks found
13:07:24.638 -> Nr | SSID | RSSI | CH | Encryption
13:07:24.678 -> 1 | DIRECT-3I-EPSON-ET-2850 Series | -65 | 10 | WPA2
13:07:24.678 -> 2 | birds aren’t real | -66 | 10 | WPA2
13:07:24.678 -> 3 | Life-Ministries | -79 | 1 | WPA2
13:07:24.709 -> 4 | SpectrumSetup-36 | -83 | 11 | WPA2
13:07:24.709 -> 5 | kooper11 | -85 | 6 | WPA2
13:07:24.709 -> 6 | SpectrumSetup-A1 | -86 | 6 | WPA2
13:07:24.709 -> 7 | NETGEAR03 | -87 | 7 | WPA2
13:07:24.743 -> 8 | Jasper | -89 | 3 | WPA2
13:07:24.743 -> 9 | CenturyLink9198 | -91 | 1 | WPA+WPA2
13:07:24.743 -> 10 | NETGEAR81 | -92 | 1 | WPA2
13:07:24.775 -> 11 | NETGEAR28 | -92 | 1 | WPA2
13:07:24.775 -> 12 | Life-Ministries | -92 | 11 | WPA2
13:07:24.775 -> 13 | VTECH_7764_391a | -94 | 1 | WPA2
13:07:24.822 ->
13:07:24.822 ->
13:07:24.822 -> Scan done
13:07:24.822 ->
13:07:24.822 -> Connecting to WiFi Network ..
13:07:24.822 ->
13:07:24.822 -> Connecting to WiFi Network ..
13:07:24.822 -> .6
13:07:30.421 -> Connecting to WiFi Network ..
13:07:30.421 -> .4
13:07:35.606 -> Connecting to WiFi Network ..
13:07:35.606 -> .4
13:07:40.618 -> Connecting to WiFi Network ..
13:07:40.618 -> .4
#include "WiFi.h"
// Replace with your own network credentials
const char* ssid = "birds aren’t real";
const char* password = "mypassword";
void setup()
{
Serial.begin(115200);
// Set WiFi to station mode and disconnect from an AP if it was previously connected.
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(5000);
// WiFi.scanNetworks will return the number of networks found.
Serial.println("Scan start");
int n = WiFi.scanNetworks();
if (n == 0) {
Serial.println("no networks found");
} else {
Serial.print(n);
Serial.println(" networks found");
Serial.println("Nr | SSID | RSSI | CH | Encryption");
for (int i = 0; i < n; ++i) {
// Print SSID and RSSI for each network found
Serial.printf("%2d",i + 1);
Serial.print(" | ");
Serial.printf("%-32.32s", WiFi.SSID(i).c_str());
Serial.print(" | ");
Serial.printf("%4d", WiFi.RSSI(i));
Serial.print(" | ");
Serial.printf("%2d", WiFi.channel(i));
Serial.print(" | ");
switch (WiFi.encryptionType(i))
{
case WIFI_AUTH_OPEN:
Serial.print("open");
break;
case WIFI_AUTH_WEP:
Serial.print("WEP");
break;
case WIFI_AUTH_WPA_PSK:
Serial.print("WPA");
break;
case WIFI_AUTH_WPA2_PSK:
Serial.print("WPA2");
break;
case WIFI_AUTH_WPA_WPA2_PSK:
Serial.print("WPA+WPA2");
break;
case WIFI_AUTH_WPA2_ENTERPRISE:
Serial.print("WPA2-EAP");
break;
case WIFI_AUTH_WPA3_PSK:
Serial.print("WPA3");
break;
case WIFI_AUTH_WPA2_WPA3_PSK:
Serial.print("WPA2+WPA3");
break;
case WIFI_AUTH_WAPI_PSK:
Serial.print("WAPI");
break;
default:
Serial.print("unknown");
}
Serial.println();
delay(10);
}
}
Serial.println("");
Serial.println("Scan done");
// Delete the scan result to free memory for code below.
WiFi.scanDelete();
// Start connection to wifi
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("\nConnecting to WiFi Network ..");
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, password);
Serial.println("\nConnecting to WiFi Network ..");
Serial.print(".");
Serial.print(WiFi.status());
delay(5000);
}
Serial.println("\nConnected to the WiFi network");
Serial.print("Local ESP32 IP: ");
Serial.println(WiFi.localIP());
Serial.println("Setup done");
}
void loop()
{
}