Does wifi connection take too long?

eyaleb
Posts: 31
Joined: Sun May 14, 2017 6:54 am

Does wifi connection take too long?

Postby eyaleb » Tue Jun 20, 2017 7:21 am

In an earlier thread (https://esp32.com/viewtopic.php?f=13&t=2066&p=9798) I asked why wifi takes so long to connect. It was a bit OT for that thread and did not attract any comment.

The timing logged by my app is this (time from gettimeofday)

Code: Select all

0.021863 esp_wifi_init
I (514) wifi: wifi firmware version: a78a223
0.081430 esp_wifi_start
I (554) wifi: wifi timer task: 3ffc5aac, prio:21, stack:3584
I (564) wifi: mode : sta (30:ae:a4:05:d8:d4)
0.105264 esp_wifi_connect
I (694) wifi: n:6 0, o:1 0, ap:255 255, sta:6 0, prof:1
I (1394) wifi: connected with eyal, channel 6
0.948120 SYSTEM_EVENT_STA_GOT_IP
A static ip is set.

On the esp8266 this sequence takes half as long. Should I expect to get better timing?

TIA

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Does wifi connection take too long?

Postby ESP_igrr » Tue Jun 20, 2017 8:39 am

Are you setting AP's channel in your wifi_config_t structure?

components/esp32/include/esp_wifi_types.h#L166

As far as I know, on the ESP8266 APs channel number is stored in flash by the SDK. On the ESP32 we don't do this by default, but you have all the pieces to implement this (perform scan, get APs channel, store into NVS, specify the channel when connecting).

(Relevant discussion in https://github.com/espressif/esp32-wifi-lib/issues/4)

eyaleb
Posts: 31
Joined: Sun May 14, 2017 6:54 am

Re: Does wifi connection take too long?

Postby eyaleb » Tue Jun 20, 2017 3:22 pm

@ESP_igrr, no, I am not setting the channel.
I now added it and it made no difference. Actually, regardless of the channel I set (1,6,11) it always connects on channel 6.

BTW, I was setting the config on first boot, but not on deep sleep wakeup. Setting it every time made no difference.

About nvs. Are you saying that esp_wifi_set_storage(WIFI_STORAGE_FLASH) will not save the channel, and I need to repeat the esp_wifi_set_config() after each wakeup? What I am doing is this:

Code: Select all

if (reset_reason != DEEPSLEEP_RESET) {
    esp_wifi_set_storage(WIFI_STORAGE_FLASH);    // (1) was not doing this before
    esp_wifi_set_mode(WIFI_MODE_STA);
    wifi_config_t wifi_config = {
        .sta = {
            .ssid     = AP_SSID,
           .password = AP_PASS,
           .bssid_set = 0,
          .channel = 11
        },
    };
    esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config);
    esp_wifi_set_auto_connect(1);               // (2) was not doing this before
}
(1) All the examples use WIFI_STORAGE_RAM, so this will not save it - right?
(2) No example does this. Is it needed? Is it the default? Is it remembered after wakeup?
If I do not issue an explicit esp_wifi_connect then I do not get a connection.

I still see connection to channel 6, and it still takes about 830ms from connect to GOT_IP.

Is there an example of doing this correctly?

TIA,
I will keep reading.

[later]
I grabbed the template example https://github.com/espressif/esp-idf-te ... ain/main.c.
I added logging to the event handler. I get the same 800+ms wifi connect time and setting the channel has no effect.
I then disabled dhcp and added tcpip_adapter_set_ip_info() which had no effect.

Code: Select all

I (1451) wifi: wifi firmware version: 195794b
I (1451) wifi: config NVS flash: enabled
I (1451) wifi: config nano formating: disabled
I (1461) wifi: Init dynamic tx buffer num: 32
I (1461) wifi: Init dynamic rx buffer num: 32
I (1461) wifi: wifi driver task: 3ffbdda0, prio:21, stack:4096
I (1471) wifi: Init static rx buffer num: 10
I (1471) wifi: Init dynamic rx buffer num: 32
I (1471) wifi: Init rx ampdu len mblock:7
I (1481) wifi: Init lldesc rx ampdu entry mblock:4
I (1481) wifi: wifi power manager task: 0x3ffc3168 prio: 19 stack: 2560
I (1491) wifi: wifi timer task: 3ffc41e8, prio:21, stack:3584
I (1501) wifi: mode : sta (30:ae:a4:05:d8:c8)
0.079181 Event 2
I (1621) wifi: n:6 0, o:1 0, ap:255 255, sta:6 0, prof:1
I (2281) wifi: state: init -> auth (b0)
I (2291) wifi: state: auth -> assoc (0)
I (2301) wifi: state: assoc -> run (10)
I (2321) wifi: connected with eyal, channel 6
0.892986 Event 4
0.893265 Event 7
I am still unclear as to the use of nvs for saving the channel. I read all the doco I could find and even nvs_flash_init() is not described clearly: does it initialize access to nvs (like unix 'mount') or does it clear it (like unix 'mkfs')?

Does esp_wifi_set_storage(WIFI_STORAGE_RAM) mean "set config in memory but do not save to flash"? If so, then one must first write to flash at lease once (I do not see the examples doing this)?

My test app is here https://github.com/makehackvoid/ESP8266 ... f/template

... I will keep reading...

littlesky
Posts: 51
Joined: Fri Jun 09, 2017 7:49 am

Re: Does wifi connection take too long?

Postby littlesky » Tue Jan 08, 2019 7:12 am

@eyaleb Please try this

Code: Select all

    wifi_config_t wifi_config = {
        .sta = {
            .ssid     = AP_SSID,
           .password = AP_PASS,
           .scan_method = WIFI_FAST_SCAN,
           .bssid_set = 0,
        },
    };

Who is online

Users browsing this forum: Baidu [Spider] and 111 guests