Clients can't connect to ESP32 SoftAP. Not getting IP address

fbautista
Posts: 4
Joined: Tue Dec 03, 2019 11:27 pm

Clients can't connect to ESP32 SoftAP. Not getting IP address

Postby fbautista » Mon Jan 06, 2020 9:20 pm

Hi,

I've been using the ESP32 WIFI in SoftAP mode. After some tests I am observing certain clients randomly disconnects and won't be able to connect anymore. Below is a debug when this event occurs:

Code: Select all

I (1683272) wifi: station: 00:12:9f:00:97:77 leave, AID = 2, bss_flags is 131121, bss:0x3ffcaf9c
I (1683272) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1683272) WIFI_SOFT_AP: station 00:12:9f:00:97:77 leave, AID=2
I (1693232) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1693242) wifi: station: 00:12:9f:00:97:77 join, AID=2, b, 20
I (1693292) WIFI_SOFT_AP: station 00:12:9f:00:97:77 join, AID=2
I (1703222) wifi: station: 00:12:9f:00:97:77 leave, AID = 2, bss_flags is 131121, bss:0x3ffcaf9c
I (1703222) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1703222) WIFI_SOFT_AP: station 00:12:9f:00:97:77 leave, AID=2
I (1713222) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1713222) wifi: station: 00:12:9f:00:97:77 join, AID=2, b, 20
I (1713272) WIFI_SOFT_AP: station 00:12:9f:00:97:77 join, AID=2
I (1723212) wifi: station: 00:12:9f:00:97:77 leave, AID = 2, bss_flags is 131121, bss:0x3ffcaf9c
I (1723212) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1723212) WIFI_SOFT_AP: station 00:12:9f:00:97:77 leave, AID=2
I (1733372) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1733372) wifi: station: 00:12:9f:00:97:77 join, AID=2, b, 20
I (1733422) WIFI_SOFT_AP: station 00:12:9f:00:97:77 join, AID=2
I (1743252) wifi: station: 00:12:9f:00:97:77 leave, AID = 2, bss_flags is 131121, bss:0x3ffcaf9c
I (1743252) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1743252) WIFI_SOFT_AP: station 00:12:9f:00:97:77 leave, AID=2
I (1753352) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1753352) wifi: station: 00:12:9f:00:97:77 join, AID=2, b, 20
I (1753402) WIFI_SOFT_AP: station 00:12:9f:00:97:77 join, AID=2
I (1773202) wifi: station: 00:12:9f:00:97:77 leave, AID = 2, bss_flags is 131121, bss:0x3ffcaf9c
I (1773202) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1773202) WIFI_SOFT_AP: station 00:12:9f:00:97:77 leave, AID=2
I (1783452) wifi: new:<1,0>, old:<1,0>, ap:<1,1>, sta:<255,255>, prof:1
I (1783452) wifi: station: 00:12:9f:00:97:77 join, AID=2, b, 20
It appears to join the wifi network. The esp32 assigns it an AID but not an IP address. Then, after several minutes it leaves network. Below is my code for the wifi setup:

Code: Select all

static void wifi_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;
        ESP_LOGI(WIFI_TAG, "station "MACSTR" join, AID=%d",
                 MAC2STR(event->mac), event->aid);
    } else if (event_id == WIFI_EVENT_AP_STADISCONNECTED) {
        wifi_event_ap_stadisconnected_t* event = (wifi_event_ap_stadisconnected_t*) event_data;
        ESP_LOGI(WIFI_TAG, "station "MACSTR" leave, AID=%d",
                 MAC2STR(event->mac), event->aid);
    }
}

void wifi_init_softap(void)
{
    esp_netif_init();
    ESP_ERROR_CHECK(esp_event_loop_create_default());
    esp_netif_t* wifiAP = esp_netif_create_default_wifi_ap();

    esp_netif_ip_info_t ipInfo;
    IP4_ADDR(&ipInfo.ip, 192,168,2,1);
	IP4_ADDR(&ipInfo.gw, 192,168,2,1);
	IP4_ADDR(&ipInfo.netmask, 255,255,255,0);
	esp_netif_dhcps_stop(wifiAP);
	esp_netif_set_ip_info(wifiAP, &ipInfo);
	esp_netif_dhcps_start(wifiAP);


    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK(esp_wifi_init(&cfg));

    ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL));

    wifi_config_t wifi_config = {
        .ap = {
            .ssid = EXAMPLE_ESP_WIFI_SSID,
            .ssid_len = strlen(EXAMPLE_ESP_WIFI_SSID),
            .password = EXAMPLE_ESP_WIFI_PASS,
            .max_connection = EXAMPLE_MAX_STA_CONN,
            .authmode = WIFI_AUTH_WPA_WPA2_PSK
        },
    };
    if (strlen(EXAMPLE_ESP_WIFI_PASS) == 0) {
        wifi_config.ap.authmode = WIFI_AUTH_OPEN;
    }

    ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
    ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_config));
    ESP_ERROR_CHECK(esp_wifi_start());

    ESP_LOGI(WIFI_TAG, "wifi_init_softap finished. SSID:%s password:%s",
             EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);

}
Furthermore when I try to connect with my android phone, it's unable to connect at all and I am getting 'Can't get IP address' error. Any one knows what's causing this?

Thanks!

gal-vayyar
Posts: 8
Joined: Sun Jun 21, 2020 3:12 pm

Re: Clients can't connect to ESP32 SoftAP. Not getting IP address

Postby gal-vayyar » Mon Nov 09, 2020 5:19 pm

I got the exactly same thing. Did you solve it by any chance?

Scott.Bonomi
Posts: 73
Joined: Mon Mar 09, 2020 7:36 pm

Re: Clients can't connect to ESP32 SoftAP. Not getting IP address

Postby Scott.Bonomi » Wed Nov 11, 2020 9:19 pm

I have have is probably a similar situation.
It looks like normal state engine progression until:

[0mD (23816) wpa: wpa_rx: new eapol=0x3ffd4fc4
[0mD (23820) wpa: WPA: f0:08:d1:6b:36:fc WPA_PTK entering state PTKINITDONE
[0mD (23827) system_event: SYSTEM_EVENT_AP_STACONNECTED, mac:f0:08:d1:6b:36:fc, aid:1
[0mD (23836) event: running post WIFI_EVENT:14 with handler 0x400dbc20 on loop 0x3ffc81a4
[0m
[0;32mI (23843) wifi softAP: station f0:08:d1:6b:36:fc join, AID=1[0m
[0;32mI (23901) tcpip_adapter: softAP assign IP to station,IP is: 192.168.4.2
[0mD (23901) system_event: SYSTEM_EVENT_AP_STAIPASSIGNED
[0mD (23902) event: no handlers have been registered for event IP_EVENT:2 posted to loop 0x3ffc81a4
[0m

I am using code and calls from the esp-idf\examples\protocols\http_server\simple example,
which works standalone, wrapped into another main function. I have a bit of an unexplained anomaly, The package runs on a DevCKit, either with the original Solo-1 or with the processor swapped to a ESP32-U4WDH part, and the SPI Flash chip removed. The same code on our Custom Board fails to connect and stops at the point above. I do not see a specific error message about failing to start a thread with the ESP_LOGx set to verbose.
Suggestions as to a more correct base would be appreciated. I do need reliable WiFi eventually.

Using the 4.0.2 toolchain at this point. When I tried 4.1 a couple months back it seemed that the interface to both SPI and WiFi failed to compile.

axellin
Posts: 197
Joined: Mon Sep 17, 2018 9:09 am

Re: Clients can't connect to ESP32 SoftAP. Not getting IP address

Postby axellin » Thu Nov 12, 2020 1:34 am


Who is online

Users browsing this forum: No registered users and 139 guests