In my application, I am using light sleep and periodically waking up and using esp now. I want the time awake to be an absolute minimum. I use the following code:
esp_sleep_enable_timer_wakeup(SLEEP_US);
esp_wifi_stop();
esp_light_sleep_start();
esp_wifi_start();
For the first cycle, the esp_wifi_stop() call takes 1ms and the esp_wifi_start() takes 7-8ms. For subsequent cycles though this code, the esp_wifi_stop() takes 9ms. There is an important distinction between the first and subsequent loops. The first call to esp_wifi_stop() is before any esp_now_send calls, whereas others are not. I can see if I remove the esp_now_send call between sleeps, the esp_wifi_stop() call remains at 1ms duration.
9ms seems like a long time to turn off the WiFi. Is there any way this, and for that matter esp_wifi_start() can be sped up as a 19ms overhead is massive for my application?
PS: I have played with reducing the cpu mhz during the esp_wifi_stop() and esp_wifi_stop() calls and it slows them down a lot.