Very slow Wifi initialization with Wifi Kit 32

I am using ESP-IDF on a Wifi Kit 32 board. I’m noticing that all of the examples I have tried from the esp-idf sources have VERY slow Wifi initialization. Using menuconfig I found I had to change the Main XTAL frequency option to 26 MHz from the default of 40 MHz. I also changed the CPU frequency to 240 MHz instead of 160 MHz and set RTC clock source to External 32kHz crystal. This made it to where it at least boots properly and the serial monitor works.

From the serial port monitor it looks like the system is booting up, but with the default DHCP configuration, it takes around 8 minutes before a DHCP IP address is obtained! I then tried assigning a static IP address with esp_netif_set_ip_info() which works, but still takes around 40 seconds before I can ping the device or communicate with a listening TCP port. I thought it was perhaps a poor connection, since my router is reporting a rather poor connection, despite being just 1 room away, so I put it right next to the router, without any improvement and it is still showing around -81dBm of signal strength, despite being a couple feet from the router. I don’t think it is because of the poor connection though, since it seems to take a fairly consistent amount of time to be usable (8 minutes with DHCP and 40 seconds with static IP). The Wifi AP connection appears to happen fairly quickly in both cases. In the case of a static IP, it also gets a callback fairly quickly with the IP address, it is just that the interface doesn’t work yet. In the case of DHCP it takes around 8 minutes to get an IP assigned and the event callback to be triggered.

Are there perhaps some other settings I need to change from the default Espressif board settings for the Heltec Wifi Kit 32?

Any ideas or tips on this would be much appreciated.

Here is an excerpt from the log for the static IP case:
I (906) wifi:connected with ElementsOfSound, aid = 3, channel 11, BW20, bssid = 60:e3:27:4e:03:20
I (906) wifi:security: Open Auth, phy: bg, rssi: -55
I (916) wifi:pm start, type: 1

I (916) tcp_server: got ip:192.168.0.72
I (926) esp_netif_handlers: sta ip: 192.168.0.72, mask: 255.255.255.0, gw: 192.168.0.2
I (996) wifi:AP’s beacon interval = 102400 us, DTIM period = 2
I (39816) tcp_server: Socket accepted ip address: 192.168.0.10

As can be seen the Wifi connection happens within 1 second of booting, but the TCP connection doesn’t occur until almost 40 seconds later.

You can try to use the Arduino development environment.

I just gave an Arduino example a try and it works as expected (can connect immediately after startup). I much prefer the esp-idf environment though to Arduino and am not really willing to switch. If I can’t get the wireless to work correctly on the Wifi Kit 32 with esp-idf, I will just use another ESP32 platform. I am going to put in some more effort though to try and track down the issue.

I enabled LWIP logging and ESP verbose logging and found that it looks like LWIP is receiving packets (ARPs, TCP/IP connection requests , etc) from the wireless interface, but transmit packets don’t reach the network. I traced the call chain by adding debug messages as far as esp_wifi_internal_tx() which returns ESP_OK, but that appears to be a private function, so I can look no further.

Any ideas why esp_wifi_internal_tx() would fail to actually transmit a packet? Eventually (after around 30 seconds after boot) transmits start to work.