In order to connect to Wifi from ESP32 and other boards, the WiFi connection needs to be 2.4GHz, wireless mode must be legacy. It cannot be set to Auto or N only. Go to your router box web page, and change this setting under Advanced Settings > Wireless.
The only code required to connect is.
void loopsetup() {
...
WiFi.begin(MY_SSID, MY_PWD);
}
void setuploop() {
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
...
}