-->
Page 1 of 1

Connecting to WIFI after esp_light_sleep_start()

PostPosted: Wed Dec 30, 2020 9:05 am
by blueSpirit
Hello,
I ve a ESP-12F board. It shall sleep until it gets an interrupt (GPIO) and then immediately notify a server via WIFI and then sleep again - till the next interrupt.

I ve created an example program for testing, see user_main.c on github.com.

It sends two messages via UDP, then sleeps 5 seconds and sends the two messages again:
Code: Select all   while (1) {
      for (int cnt=0; cnt < 2; cnt++) {
         send_udp_packet();
         sleep(1);
      }
      ESP_ERROR_CHECK( esp_wifi_stop() );
      ESP_ERROR_CHECK( esp_sleep_enable_timer_wakeup(5*1000*1000) );
      ESP_LOGE(TAG, " ---> enter light sleep");
      ESP_ERROR_CHECK( esp_light_sleep_start() );
      ESP_LOGE(TAG, " ---> returned from light sleep");
      ESP_ERROR_CHECK( esp_wifi_start() );
      sleep(6);
   }


Before going to light_sleep, the WIFI connection is established every time (100%). But after the light_sleep, fails from time to time (sometimes it works fine for 70 cycles - but sometimes it fails on the second sleep):
Code: Select all14:44:10 E (24108) app:  ---> returned from light sleep
14:44:10 I (24115) app: SYSTEM_EVENT_STA_START
14:44:16 E (30112) app: Error occured during sending: Host is unreachable/118
14:44:17 E (31111) app: Error occured during sending: Host is unreachable/118
14:44:18 E (32112) app:  ---> enter light sleep


When it works fine, the output looks like this:
Code: Select all14:43:57 E (10995) app:  ---> returned from light sleep
14:43:57 I (11002) app: SYSTEM_EVENT_STA_START
14:43:57 I (11128) wifi: state: 0 -> 2 (b0)
14:43:57 I (11135) wifi: state: 2 -> 3 (0)
14:43:57 I (11145) wifi: state: 3 -> 5 (10)
14:43:57 I (11148) wifi: pm start, type: 1
14:43:57 I (11180) app: SYSTEM_EVENT_STA_CONNECTED
14:43:58 I (12171) event: sta ip: 192.168.178.200, mask: 255.255.255.0, gw: 192.168.178.1
14:43:58 I (12181) app: SYSTEM_EVENT_STA_GOT_IP
14:44:03 I (17006) app: Message 2 sent
14:44:04 I (18006) app: Message 3 sent
14:44:05 I (19003) wifi: state: 5 -> 0 (0)
14:44:05 I (19007) wifi: pm stop
14:44:05 I (19010) app: SYSTEM_EVENT_STA_DISCONNECTED
14:44:05 I (19018) app: SYSTEM_EVENT_STA_STOP
14:44:05 E (19103) app:  ---> enter light sleep


This is the same trace, when the wifi debugs are enabled:
Code: Select all14:57:55 E (10827) app:  ---> returned from light sleep
14:57:55 I (10833) wifi: mode : sta (ec:fa:bc:a7:43:64)
14:57:55 I (10836) wifi: add if0
14:57:55 I (10839) app: SYSTEM_EVENT_STA_START
14:57:55 D (10843) wifi: first chan=1
14:57:55 D (10845) wifi: cnx_start_connect 50f
14:57:55 D (10851) wifi: scan_cancel 3
14:57:55 D (10855) wifi: scan_op_end 0 4
14:57:55 D (10859) wifi: enter scan_done 4838845 1
14:57:55 I (10865) wifi: scandone
14:57:55 D (10870) wifi: first chan=1
14:57:55 D (10874) wifi: cnx_start_handoff_cb
14:57:55 D (10879) wifi: failed
14:57:55 D (10882) wifi: scan start 4861963
14:57:55 D (10887) wifi: scan_inter_channel_timeout 1
14:57:55 D (10893) wifi: rd: chan=1 active max=11
14:57:55 D (10899) wifi: scan_op_start 2412 1
14:57:55 D (10904) wifi: rd: chan=1 active max=11
14:57:55 D (10910) wifi: scan_send_probe
14:57:55 D (10914) wifi: ucast probe
14:57:55 D (10918) wifi: send probe req on channel 1 bssid ff:ff:ff:ff:ff:ff ssid Eckbank
14:58:01 E (16842) app: Error occured during sending: Host is unreachable/118
14:58:02 E (17843) app: Error occured during sending: Host is unreachable/118
14:58:03 D (18842) wifi: scan_cancel 7
14:58:03 D (18844) wifi: scan_op_end 0 4
14:58:03 D (18846) wifi: enter scan_done 12827271 1
14:58:03 I (18849) wifi: scandone
14:58:03 D (18850) wifi: first chan=1
14:58:03 D (18852) wifi: cnx_start_handoff_cb
14:58:03 D (18855) wifi: failed
14:58:03 I (18859) wifi: del if0
14:58:03 I (18864) wifi: usl
14:58:03 D (18867) wifi: sul 0 0
14:58:03 E (18871) app:  ---> enter light sleep


I'm using the `ESP8266_RTOS_SDK` from branch `release/v3.3`, together with the `xtensa-lx106 1.22.0-100-ge567ec7`. The setup is downloaded/installed by setup.sh.

Is there something wrong in my code? Do I need additional sleeps? It's really a pity that the wifi code is closed source!

BR, Karl