IP_EVENT_AP_STAIPASSIGNED is never called in AP-Mode
Posted: Wed May 17, 2023 1:42 pm
This is my AP init code:
and this the event handler:
Unfortunately, IP_EVENT_AP_STAIPASSIGNED is never called.
Does somebody have an idea why this is the case? Once a station connects to the AP, it reports:
Code: Select all
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_netif_create_default_wifi_ap();
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
ESP_EVENT_ANY_ID,
&wifi_ap_event_handler,
NULL,
NULL));
wifi_config_t wifi_config = {
.ap = {
.ssid = EXAMPLE_ESP_WIFI_SSID,
.ssid_len = strlen(EXAMPLE_ESP_WIFI_SSID),
.channel = 1,
.password = EXAMPLE_ESP_WIFI_PASS,
.max_connection = 1,
.authmode = WIFI_AUTH_WPA2_PSK,
.pmf_cfg = {
.required = true,
},
},
};
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
Code: Select all
static void wifi_ap_event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data) {
if (event_id == WIFI_EVENT_AP_STACONNECTED) {
wifi_event_ap_staconnected_t* event = (wifi_event_ap_staconnected_t*)event_data;
printf("Station connected...\n");
} else if (event_id == IP_EVENT_AP_STAIPASSIGNED) {
ip_event_ap_staipassigned_t *event = (ip_event_ap_staipassigned_t*)event_data;
printf("Station ip assigned...\n");
last_sta_ip_address = event->ip.addr;
} else if (event_id == WIFI_EVENT_AP_STADISCONNECTED) {
wifi_event_ap_stadisconnected_t* event = (wifi_event_ap_stadisconnected_t*)event_data;
printf("Station disconnected...\n");
last_sta_ip_address = 0;
}
}
Does somebody have an idea why this is the case? Once a station connects to the AP, it reports:
So the IP assignment seems to work.esp_netif_lwip: DHCP server assigned IP to a client, IP is: 192.168.4.2