Wi-Fi auto join on boot

balix53
Posts: 27
Joined: Mon Jan 21, 2019 8:47 am

Wi-Fi auto join on boot

Postby balix53 » Wed Jun 09, 2021 2:58 pm

Hello,

I'm trying to find a way to automatically join a previously joined Wi-Fi access point after a reboot.

As far as I know this feature should do the trick: https://docs.espressif.com/projects/esp ... -nvs-flash

I used the ESP IDF station example to join first my access point: https://github.com/espressif/esp-idf/bl ... ple_main.c

Then I removed entirely the Wi-Fi configuration with my access point (i.e. I no longer try to explicitly join it) by commenting the following lines:

Code: Select all

    wifi_config_t wifi_config = {
        .sta = {
            .ssid = EXAMPLE_ESP_WIFI_SSID,
            .password = EXAMPLE_ESP_WIFI_PASS,
            /* Setting a password implies station will connect to all security modes including WEP/WPA.
             * However these modes are deprecated and not advisable to be used. Incase your Access point
             * doesn't support WPA2, these mode can be enabled by commenting below line */
	     .threshold.authmode = WIFI_AUTH_WPA2_PSK,

            .pmf_cfg = {
                .capable = true,
                .required = false
            },
        },
    };
    ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
    ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
But the connected event is never received from the driver. I assumed that, given what the documentation states, my access point would be automatically joined but it is not the case.

Am I missing something? The NVS flash is correctly enabled in my menuconfig.

Thanks,

Benjamin

plaupr
Posts: 1
Joined: Thu Jun 10, 2021 9:43 am

Re: Wi-Fi auto join on boot

Postby plaupr » Thu Jun 10, 2021 9:49 am

Hello,

We observe these connection times to Wi-Fi (WPA2) on ESP32 Wrover in IDF 4.2.1 :

Code: Select all

Event 	                                Time 	    Time since app start
cpu_start: App cpu up. 	                17:55:00.5 	00:00:00.0
wifi:mode : sta (Wi-Fi init finished) 	17:55:00.9 	00:00:00.4
wifi:connected with Livebox 	        17:55:02.9 	00:00:02.4
wifi station: got ip 	                17:55:05.1 	00:00:05.1
The total time is 5 seconds.

Do you think these results are normal for a connection to a standard Wi-Fi router?
If not what are your recommendations to optimize this time?

Thanks,

Pierre

Zombie
Posts: 4
Joined: Fri Jan 10, 2020 6:57 am

Re: Wi-Fi auto join on boot

Postby Zombie » Fri Jun 11, 2021 11:02 am

Hi Pierre

Could you please use fast scan example(https://github.com/espressif/esp-idf/tr ... /fast_scan) for wifi connection?

After testing, the fast scan example took only below 2 s on IDF 4.2.1 to successfully connect to wifi, as follows :

Code: Select all

I (46) boot: ESP-IDF v4.2.1 2nd stage bootloader
I (46) boot: compile time 18:54:20
I (46) boot: chip revision: 0
I (48) boot.esp32s2: SPI Speed      : 80MHz
I (52) boot.esp32s2: SPI Mode       : DIO
I (57) boot.esp32s2: SPI Flash Size : 2MB
I (62) boot: Enabling RNG early entropy source...
I (67) boot: Partition Table:
I (71) boot: ## Label            Usage          Type ST Offset   Length
I (78) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (86) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (93) boot:  2 factory          factory app      00 00 00010000 00100000
I (100) boot: End of partition table
I (105) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f000020 size=0x152dc ( 86748) map
I (132) esp_image: segment 1: paddr=0x00025304 vaddr=0x3ffc8430 size=0x02e9c ( 11932) load
I (135) esp_image: segment 2: paddr=0x000281a8 vaddr=0x40024000 size=0x00404 (  1028) load
0x40024000: _WindowOverflow4 at /home/zhengzhong/github/esp-idf/rel4.2/esp-idf/components/freertos/xtensa/xtensa_vectors.S:1730

I (139) esp_image: segment 3: paddr=0x000285b4 vaddr=0x40024404 size=0x07a64 ( 31332) load
I (156) esp_image: segment 4: paddr=0x00030020 vaddr=0x40080020 size=0x69ef8 (433912) map
0x40080020: _stext at ??:?

I (247) esp_image: segment 5: paddr=0x00099f20 vaddr=0x4002be68 size=0x0c5bc ( 50620) load
0x4002be68: vTaskSetTimeOutState at /home/zhengzhong/github/esp-idf/rel4.2/esp-idf/components/freertos/tasks.c:3225 (discriminator 1)

I (271) boot: Loaded app from partition at offset 0x10000
I (272) boot: Disabling RNG early entropy source...
I (272) cache: Instruction cache        : size 8KB, 4Ways, cache line size 32Byte
I (279) cpu_start: Pro cpu up.
I (283) cpu_start: Application information:
I (288) cpu_start: Project name:     fast_scan
I (293) cpu_start: App version:      v4.2.1
I (298) cpu_start: Compile time:     Jun 11 2021 18:54:12
I (304) cpu_start: ELF file SHA256:  a9d0b5758448c347...
I (310) cpu_start: ESP-IDF:          v4.2.1
I (315) cpu_start: Single core mode
I (319) heap_init: Initializing. RAM available for dynamic allocation:
I (326) heap_init: At 3FFCF738 len 0002C8C8 (178 KiB): DRAM
I (333) heap_init: At 3FFFC000 len 00003A10 (14 KiB): DRAM
I (339) cpu_start: Pro cpu start user code
I (401) spi_flash: detected chip: generic
I (401) spi_flash: flash io: dio
W (402) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (412) cpu_start: Starting scheduler on PRO CPU.
I (435) wifi:wifi driver task: 3ffd7d44, prio:23, stack:6656, core=0
I (435) system_api: Base MAC address is not set
I (435) system_api: read default base MAC address from EFUSE
I (445) wifi:wifi firmware version: c44a5e7
I (445) wifi:wifi certification version: v7.0
I (445) wifi:config NVS flash: enabled
I (445) wifi:config nano formating: disabled
I (455) wifi:Init data frame dynamic rx buffer num: 32
I (455) wifi:Init management frame dynamic rx buffer num: 32
I (465) wifi:Init management short buffer num: 32
I (465) wifi:Init dynamic tx buffer num: 32
I (475) wifi:Init static rx buffer size: 1600
I (475) wifi:Init static rx buffer num: 10
I (475) wifi:Init dynamic rx buffer num: 32
I (485) wifi_init: rx ba win: 6
I (485) wifi_init: tcpip mbox: 32
I (495) wifi_init: udp mbox: 6
I (495) wifi_init: tcp mbox: 6
I (495) wifi_init: tcp tx win: 5744
I (505) wifi_init: tcp rx win: 5744
I (505) wifi_init: tcp mss: 1440
I (515) wifi_init: WiFi IRAM OP enabled
I (515) wifi_init: WiFi RX IRAM OP enabled
I (525) phy_init: phy_version 1300,2887b9c,Dec 16 2020
I (735) wifi:enable tsf
I (735) wifi:mode : sta (7c:df:a1:01:57:d8)
I (795) wifi:new:<6,0>, old:<1,0>, ap:<255,255>, sta:<6,0>, prof:1
I (795) wifi:state: init -> auth (b0)
I (805) wifi:state: auth -> assoc (0)
I (805) wifi:state: assoc -> run (10)
I (855) wifi:connected with zztest, aid = 1, channel 6, BW20, bssid = 08:60:6e:21:48:e8
I (855) wifi:security: WPA2-PSK, phy: bgn, rssi: -28
I (855) wifi:pm start, type: 1

I (895) wifi:AP's beacon interval = 102400 us, DTIM period = 3
I (1425) scan: got ip:192.168.1.55
I (1425) esp_netif_handlers: sta ip: 192.168.1.55, mask: 255.255.255.0, gw: 192.168.1.1

balix53
Posts: 27
Joined: Mon Jan 21, 2019 8:47 am

Re: Wi-Fi auto join on boot

Postby balix53 » Tue Jun 15, 2021 6:49 am

Hi,

In my case fast scan example gives the same result (~1 s to be connected to an AP) but 4 more to get an IP adress. As a I see in your logs, acquiring an IP is much faster than that, is there any way we can cut that time? (Maybe not possible since it is the DHCP client and must depends on the AP?)

Here are my logs where we can see wifi init, AP connection and IP assignment:

Code: Select all

[6/14 09:35:24.9]I (567) phy_init: phy_version 1300,2887b9c,Dec 16 2020
[6/14 09:35:25.1]I (727) wifi:enable tsf
[6/14 09:35:25.1]I (727) wifi:mode : sta (7c:df:a1:0a:06:b4)
[6/14 09:35:25.1]I (737) wifi:new:<1,0>, old:<1,0>, ap:<255,255>, sta:<1,0>, prof:1
[6/14 09:35:25.6]I (1217) wifi:state: init -> auth (b0)
[6/14 09:35:25.6]I (1217) wifi:state: auth -> assoc (0)
[6/14 09:35:25.6]I (1217) wifi:state: assoc -> run (10)
[6/14 09:35:25.8]I (1447) wifi:connected with IS2T_GUEST, aid = 1, channel 1, BW20, bssid = 64:7c:34:68:69:8c
[6/14 09:35:25.8]I (1447) wifi:security: WPA2-PSK, phy: bgn, rssi: -46
[6/14 09:35:25.8]I (1447) wifi:pm start, type: 1
[6/14 09:35:25.8]
[6/14 09:35:25.8]I (1447) wifi:AP's beacon interval = 102400 us, DTIM period = 1
[6/14 09:35:29.8]I (5467) scan: got ip:192.168.0.45
[6/14 09:35:29.8]I (5467) esp_netif_handlers: sta ip: 192.168.0.45, mask: 255.255.255.0, gw: 192.168.0.254

Who is online

Users browsing this forum: Majestic-12 [Bot] and 221 guests