Page 1 of 1

[solved] Fail to reconnect to AP after deep sleep

Posted: Tue Dec 06, 2016 2:57 pm
by d.cook
Hello,

After waking from deep sleep, the chip appears to be unable to connect to the access point. It is able to connect normally prior to sleeping.

My test code is based on the IDF template project - once the SYSTEM_EVENT_STA_GOT_IP event is raised, esp_deep_sleep(5 * 1000000) is called. When the system wakes, this event is not triggered again even though the access point should still be available (I can connect with other devices).

EDIT: the behaviour appears to be the same if the system resets via software_reset() rather than deep sleep, so I'm not sure now if the sleep function has anything to do with this.

The system output is as follows:
ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
ets Jun 8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)

configsip: 0, SPIWP:0x00
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3ffc0008,len:0
load:0x3ffc0008,len:1964
load:0x40078000,len:3668
load:0x40080000,len:260
entry 0x40080034
entry 0x40080034
␛[0;32mI (553) heap_alloc_caps: Initializing heap allocator:␛[0m
␛[0;32mI (553) heap_alloc_caps: Region 19: 3FFD0E9C len 0000F164 tag 0␛[0m
␛[0;32mI (554) heap_alloc_caps: Region 25: 3FFE8000 len 00018000 tag 1␛[0m
␛[0;32mI (560) cpu_start: Pro cpu up.␛[0m
␛[0;32mI (564) cpu_start: Single core mode␛[0m
␛[0;32mI (568) cpu_start: Pro cpu start user code␛[0m
␛[0;32mI (584) rtc: rtc v160 Nov 22 2016 19:00:05␛[0m
␛[0;32mI (591) rtc: XTAL 26M␛[0m
␛[0;32mI (857) phy: phy_version: 258, Nov 29 2016, 15:51:07, 1, 0␛[0m
␛[0;32mI (1888) cpu_start: Starting scheduler on PRO CPU.␛[0m
tcpip_task_hdlxxx : 3ffd4944, prio:18,stack:2048

I (12125) wifi: frc2_timer_task_hdl:3ffd6454, prio:22, stack:2048
I (12129) wifi: pp_task_hdl : 3ffd8cc4, prio:23, stack:8192
I (12130) wifi: mode : sta (24:0a:c4:00:a4:08)
I (13003) wifi: n:6 0, o:1 0, ap:255 255, sta:6 0, prof:1
I (13652) wifi: state: init -> auth (b0)
I (13654) wifi: state: auth -> assoc (0)
I (13669) wifi: state: assoc -> run (10)
I (13685) wifi: connected with MysaHub, channel 6
␛[0;32mI (16754) event: ip: 10.0.1.149, mask: 255.255.255.0, gw: 10.0.1.4␛[0m
ets Jun 8 2016 00:22:57

rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)

configsip: 0, SPIWP:0x00
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3ffc0008,len:0
load:0x3ffc0008,len:1964
load:0x40078000,len:3668
load:0x40080000,len:260
entry 0x40080034
␛[0;32mI (552) heap_alloc_caps: Initializing heap allocator:␛[0m
␛[0;32mI (552) heap_alloc_caps: Region 19: 3FFD0E9C len 0000F164 tag 0␛[0m
␛[0;32mI (553) heap_alloc_caps: Region 25: 3FFE8000 len 00018000 tag 1␛[0m
␛[0;32mI (560) cpu_start: Pro cpu up.␛[0m
␛[0;32mI (564) cpu_start: Single core mode␛[0m
␛[0;32mI (568) cpu_start: Pro cpu start user code␛[0m
␛[0;32mI (584) rtc: rtc v160 Nov 22 2016 19:00:05␛[0m
␛[0;32mI (591) rtc: XTAL 26M␛[0m
␛[0;32mI (657) phy: phy_version: 258, Nov 29 2016, 15:51:07, 1, 1␛[0m
␛[0;32mI (658) cpu_start: Starting scheduler on PRO CPU.␛[0m
tcpip_task_hdlxxx : 3ffd48f4, prio:18,stack:2048
I (10936) wifi: frc2_timer_task_hdl:3ffd6440, prio:22, stack:2048
I (10951) wifi: pp_task_hdl : 3ffd8cb0, prio:23, stack:8192
I (10952) wifi: mode : sta (24:0a:c4:00:a4:08)
I (11825) wifi: n:6 0, o:1 0, ap:255 255, sta:6 0, prof:1
I (12474) wifi: state: init -> auth (b0)
I (12476) wifi: state: auth -> assoc (0)
I (12482) wifi: state: assoc -> run (10)
I (12482) wifi: state: run -> auth (2c0)
I (12483) wifi: n:6 0, o:6 0, ap:255 255, sta:6 0, prof:1

hangs here waiting for IP
If this is not a bug, is there some special action that needs to be taken to prepare networking after deep sleep?


Thanks

Re: Fail to reconnect to AP after deep sleep

Posted: Wed Dec 07, 2016 6:12 pm
by ESP_igrr
At this point I would suggest to disconnect from the AP gracefully: call esp_wifi_disconnect, then wait for SYSTEM_EVENT_STA_DISCONNECTED event, then proceed to enter deep sleep.

We do have a plan to implement "maintain AP connection while in deep sleep" feature at some point, but it won't come in the nearest release for sure.

Re: Fail to reconnect to AP after deep sleep

Posted: Mon Dec 12, 2016 5:52 pm
by d.cook
That did the trick, thanks!

Re: Fail to reconnect to AP after deep sleep

Posted: Thu Jul 12, 2018 1:53 pm
by MilCas
ESP_igrr wrote:At this point I would suggest to disconnect from the AP gracefully: call esp_wifi_disconnect, then wait for SYSTEM_EVENT_STA_DISCONNECTED event, then proceed to enter deep sleep.

We do have a plan to implement "maintain AP connection while in deep sleep" feature at some point, but it won't come in the nearest release for sure.
Hi Igrr, my question is the same do we have now in ESP32 the "maintain AP connection while in deep sleep" or a way that it can remember the wifi configuration after waking up yet or we have to wait? is there any workaround?
i am doing my master thesis which a part of it is comparing the performance of the esp32 and esp8266, so conclusion is right now esp32 connection time to a AP is around 1.3-1.4 sec. but esp32 400-600 ms. i need to reduce esp32 connection time to AP as this is a battery powered project.