Closed roblatour closed 1 year ago
Regarding https://github.com/roblatour/WeatherStation/blob/cdf04e0e0bd931095254a0b11b61f24d7053ff7d/main/main.c#L845, please do note that we don't support entering light sleep manually when communication peripherals (such as Wi-Fi) are working.
Quoting the docs,
Before entering Deep-sleep or Light-sleep modes, the application must disable Wi-Fi and Bluetooth using the appropriate calls
Basically, communication drivers make no attempt to preserve the connection if the drivers weren't stopped (e.g. esp_wifi_stop
) before entering light sleep.
Note that there is another mechanism, automatic light sleep, which allows the system to enter light sleep whenever all tasks are idle. In automatic light sleep more communication drivers can preserve the connection, and will automatically wake up the chip when appropriate, for example to receive a beacon frame. Note that this mechanism is already enabled by default in the itwt example.
To conclude, if you need to keep Wi-Fi connection (especially with Wi-Fi 6 and ITWT), do not use esp_light_sleep_start
) and let the system use the automatic light sleep mode, instead. In this case association with the AP will be maintained.
Thank you, I had missed that.
I am currently in the process of updating my program to use automatic light sleep.
When I have it updated, I will run some power comparisons for using automatic light sleep to keep the WiFi 6 connection alive, vs using deep sleep and having the program need to reconnect and post them on my github page referenced above - this to help anyone who stumbles across this post in the future.
As an aside, in working my way thru the itwt example (https://github.com/espressif/esp-idf/blob/release/v5.1/examples/wifi/itwt/main/itwt.c ) I notice the following code which I though a little odd:
static void connect_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { ESP_LOGI(TAG, "sta connect to %s", DEFAULT_SSID); esp_wifi_connect(); }
More specifically, the that connect handler calls esp_wifi_connect().
In my code I have taken this line out and it works fine.
Is there a reason that it is there?
@roblatour esp_wifi_connect
may be called elsewhere in your code, need to check it.
@roblatour More often then not, esp_wifi_connect
is often used in the handlers to deal with reconnections; however, in this case I believe the name connect_handler
is a bit of a misnomer as it has nothing to do with "connecting" but instead catching the event when the WIFI_STATION actually starts and is ready to connect to the AP. But I can see how this could be up to personal interpretation.
@dgduncan @esp-lis Thanks I hadn't noticed that in the itwt example the connect_handler was being assigned to handle the start event.
In my code, I had added the esp_wifi_connect() within an event handler I had more appropriately named start_handler, so it was working fine - but I got confused when I looked back at the example and the esp_wifi_connect() was under the (I agree misnamed) connect_handler.
Answers checklist.
IDF version.
v5.1-beta1-378-gea5e0ff298
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
None
Development Kit.
esp32-c6 devkitC-1 v1.2
Power Supply used.
USB
What is the expected behavior?
ESP should retain Wi-Fi 6 connect through light sleep.
What is the actual behavior?
ESP is losing Wi-Fi 6 connect through light sleep ( in general when light sleep > 3 minutes).
Steps to reproduce.
Code is here: https://github.com/roblatour/WeatherStation
Run with the following options in general_user_settings.h WORKAROUND 0 GENERAL_USER_SETTINGS_REPORTING_FREQUENCY_IN_MINUTES 15
Here is an example of the log when light sleep is set to 3 minutes:
Note the second and third cycle times are much less than the first cycle thanks to Wi-Fi 6 and the retained session.
In contrast, here is an example of the (partial) log when light sleep is set to 15 minutes - the full log's text is shown in the next section below:
Note the second cycle time is much greater here than in the first example due to the need to reconnect.
Debug Logs.
More Information.
I have tested with each of: esp_wifi_set_ps(WIFI_PS_MAX_MODEM); esp_wifi_set_ps(WIFI_PS_MIN_MODEM); esp_wifi_set_ps(WIFI_PS_NONE); and with not setting the ps option at all same results in all cases.
Wi-Fi connection is established using my country code (CA for Canada)
The problem appears to happen less often with shorter sleep periods (for example once every 3 minutes or less), but definitely happen with longer sleep periods (for example 15 minutes).
The problem does not occur if instead of a 15 minute light sleep, the code uses a 15 minute VTaskDelay.