Just as some added information... I tried your code on my ESP32 I'm running ESP-IDF 4.4.2. I am using the default sdkconfig settings.
Note that I updated your event handler to explicitly identify more events just to see better what was happening. So the log output reflects this change:
Code: Select all
static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
{
ESP_LOGI(TAG, "event_base = %i, event_id = %i", (int16_t) *event_base, (int16_t) event_id);
if ((event_base == WIFI_EVENT) && (event_id == WIFI_EVENT_STA_START)) {
ESP_LOGI(TAG, "STA start");
connect_timer = 1;
}
else if ((event_base == WIFI_EVENT) && (event_id == WIFI_EVENT_AP_START)) {
ESP_LOGI(TAG, "AP start");
connect_timer = 1;
}
else if ((event_base == WIFI_EVENT) && (event_id == WIFI_EVENT_STA_CONNECTED)) {
ESP_LOGI(TAG, "STA connected");
}
else if ((event_base == WIFI_EVENT) && (event_id == WIFI_EVENT_AP_STACONNECTED)) {
ESP_LOGI(TAG, "AP STA connected");
}
else if ((event_base == WIFI_EVENT) && (event_id == WIFI_EVENT_STA_DISCONNECTED)) {
ESP_LOGI(TAG, "STA Disconnect");
connect_timer = 1;
}
else if ((event_base == WIFI_EVENT) && (event_id == WIFI_EVENT_AP_STADISCONNECTED)) {
ESP_LOGI(TAG, "AP STA Disconnect");
connect_timer = 1;
}
else if ((event_base == IP_EVENT) && (event_id == IP_EVENT_STA_GOT_IP)) {
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
}
else {
ESP_LOGE(TAG, "Unknown event");
}
}
Code: Select all
I (27) boot: ESP-IDF v4.4.2-dirty 2nd stage bootloader
I (27) boot: compile time 09:50:21
I (27) boot: chip revision: 1
I (31) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (38) boot.esp32: SPI Speed : 40MHz
I (42) boot.esp32: SPI Mode : DIO
I (47) boot.esp32: SPI Flash Size : 2MB
I (51) boot: Enabling RNG early entropy source...
I (57) boot: Partition Table:
I (60) boot: ## Label Usage Type ST Offset Length
I (68) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (75) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (83) boot: 2 factory factory app 00 00 00010000 00100000
I (90) boot: End of partition table
I (94) boot_comm: chip revision: 1, min. application chip revision: 0
I (101) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=12dd4h ( 77268) map
I (138) esp_image: segment 1: paddr=00022dfc vaddr=3ffb0000 size=03804h ( 14340) load
I (144) esp_image: segment 2: paddr=00026608 vaddr=40080000 size=09a10h ( 39440) load
I (160) esp_image: segment 3: paddr=00030020 vaddr=400d0020 size=6d8b8h (448696) map
I (323) esp_image: segment 4: paddr=0009d8e0 vaddr=40089a10 size=0aad0h ( 43728) load
I (341) esp_image: segment 5: paddr=000a83b8 vaddr=50000000 size=00010h ( 16) load
I (351) boot: Loaded app from partition at offset 0x10000
I (351) boot: Disabling RNG early entropy source...
I (363) cpu_start: Pro cpu up.
I (364) cpu_start: Starting app cpu, entry point is 0x40081198
I (0) cpu_start: App cpu up.
I (378) cpu_start: Pro cpu start user code
I (378) cpu_start: cpu freq: 160000000
I (378) cpu_start: Application information:
I (382) cpu_start: Project name: app-template
I (388) cpu_start: App version: 1
I (392) cpu_start: Compile time: Oct 29 2022 09:47:23
I (398) cpu_start: ELF file SHA256: d4f52920418d8785...
I (404) cpu_start: ESP-IDF: v4.4.2-dirty
I (410) heap_init: Initializing. RAM available for dynamic allocation:
I (417) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (423) heap_init: At 3FFB74C8 len 00028B38 (162 KiB): DRAM
I (429) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (435) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (442) heap_init: At 400944E0 len 0000BB20 (46 KiB): IRAM
I (449) spi_flash: detected chip: gd
I (452) spi_flash: flash io: dio
W (456) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Usin g the size in the binary image header.
I (470) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (589) wifi:wifi driver task: 3ffbfef0, prio:23, stack:6656, core=0
I (589) system_api: Base MAC address is not set
I (589) system_api: read default base MAC address from EFUSE
I (609) wifi:wifi firmware version: eeaa27d
I (609) wifi:wifi certification version: v7.0
I (609) wifi:config NVS flash: enabled
I (609) wifi:config nano formating: disabled
I (619) wifi:Init data frame dynamic rx buffer num: 32
I (619) wifi:Init management frame dynamic rx buffer num: 32
I (629) wifi:Init management short buffer num: 32
I (629) wifi:Init dynamic tx buffer num: 32
I (639) wifi:Init static rx buffer size: 1600
I (639) wifi:Init static rx buffer num: 10
I (639) wifi:Init dynamic rx buffer num: 32
I (649) wifi_init: rx ba win: 6
I (649) wifi_init: tcpip mbox: 32
I (659) wifi_init: udp mbox: 6
I (659) wifi_init: tcp mbox: 6
I (659) wifi_init: tcp tx win: 5744
I (669) wifi_init: tcp rx win: 5744
I (669) wifi_init: tcp mss: 1440
I (669) wifi_init: WiFi IRAM OP enabled
I (679) wifi_init: WiFi RX IRAM OP enabled
I (699) main.c: start AP STA
I (699) main.c: IP: 192.168.4.1
I (699) main.c: GW: 192.168.4.1
I (699) main.c: Mask: 255.255.255.0
I (709) main.c: wifi_init_softap finished. SSID: test123 password: mypassword
I (709) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
I (809) wifi:mode : sta (30:83:98:fa:77:dc) + softAP (30:83:98:fa:77:dd)
I (809) wifi:enable tsf
I (819) wifi:Total power save buffer number: 16
I (819) wifi:Init max length of beacon: 752/752
I (819) wifi:Init max length of beacon: 752/752
I (819) main.c: event_base = 87, event_id = 2
I (829) main.c: STA start
I (829) main.c: event_base = 87, event_id = 12
I (839) main.c: AP start
I (3829) wifi:ap channel adjust o:1,1 n:9,2
I (3829) wifi:new:<9,0>, old:<1,1>, ap:<9,2>, sta:<9,0>, prof:1
I (3839) wifi:state: init -> auth (b0)
I (3839) wifi:state: auth -> assoc (0)
I (3839) wifi:state: assoc -> run (10)
W (3849) wifi:<ba-add>idx:0 (ifx:0, 3c:84:6a:82:57:68), tid:7, ssn:0, winSize:64
I (3859) wifi:connected with externalSSID, aid = 12, channel 9, BW20, bssid = 3c:84:6a:82:57:68
I (3859) wifi:security: WPA2-PSK, phy: bgn, rssi: -33
I (3869) wifi:pm start, type: 1
I (3869) main.c: event_base = 87, event_id = 4
I (3869) main.c: STA connected
W (3879) wifi:<ba-add>idx:1 (ifx:0, 3c:84:6a:82:57:68), tid:6, ssn:0, winSize:64
I (3889) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (4579) main.c: event_base = 73, event_id = 0
I (4579) main.c: got ip:192.168.1.67
I (4579) esp_netif_handlers: sta ip: 192.168.1.67, mask: 255.255.255.0, gw: 192.168.1.1
I (17399) wifi:new:<9,0>, old:<9,0>, ap:<9,2>, sta:<9,0>, prof:1
I (17399) wifi:station: 98:b8:ba:01:f9:37 join, AID=1, bgn, 20
I (17429) main.c: event_base = 87, event_id = 14
I (17439) main.c: AP STA connected
W (17509) wifi:<ba-add>idx:2 (ifx:1, 98:b8:ba:01:f9:37), tid:0, ssn:0, winSize:64
I (17689) esp_netif_lwip: DHCP server assigned IP to a station, IP is: 192.168.4.2
I (43909) wifi:station: 98:b8:ba:01:f9:37 leave, AID = 1, bss_flags is 658547, bss:0x3ffc6edc
I (43909) wifi:new:<9,0>, old:<9,0>, ap:<9,2>, sta:<9,0>, prof:1
W (43909) wifi:<ba-del>idx
I (43919) main.c: event_base = 87, event_id = 15
I (43919) main.c: AP STA Disconnect
I (65349) wifi:new:<9,0>, old:<9,0>, ap:<9,2>, sta:<9,0>, prof:1
I (65349) wifi:station: 98:b8:ba:01:f9:37 join, AID=1, bgn, 20
I (65379) main.c: event_base = 87, event_id = 14
I (65379) main.c: AP STA connected
W (65429) wifi:<ba-add>idx:2 (ifx:1, 98:b8:ba:01:f9:37), tid:0, ssn:0, winSize:64
I (65559) esp_netif_lwip: DHCP server assigned IP to a station, IP is: 192.168.4.2