Hi Folks,
its been a while since my last post. In that time i learned a lot about the ESP32. In my oppinion its a amazing device. Ive developed a few applications so far. One of them is a time critical Application which uses WiFi, and works the following steps:
- Wake from DeepSleep and Boot-Up
- Do some processing at low CPU clock
- switch to full speed (240Mhz) and Enable Wifi
- Connect to a WPA2 Network (AP Channel 1-11, Active Scan, no DHCP)
- Send a UDP multicast packet
- Go to Deepsleep
Iam able to do this job in approx 1000ms. This is still a very good value. So far i have done all optimizations i can do, e.g. multithreading, release build, flash access mode 80MHz qout, refactoring etc. But maybe there are more options for optimizations. At the moment i focus on the behaviour during Wifi connect. What i know so far is:
1) At WifiStart the ESP initializes wifi
2) With wifi connect (called from event loop) the ESP performs an active Wifi-Fast-Scan on the specified channel where the Wifi AP is supposed to be (which is not Channel 12 or 13). This takes approx. 120ms, when the AP could be found. Otherwise the scan will be continued for all other channels (i guess).
3) Then the ESP trys to connect to the AP which takes about 600-700ms @ 240MHz CPU clock.
Most of the actions performed above i can see with a fairly accurate monitoring of the power consumption of the ESP. Out of this information here are my Questions:
- Is it possible, or is there any chance to get the information if the AP could be found on the specific Wifi Channel after the single channel scan was performed, instead of continuing the wifi scan any other channel? Or can i maybe define how many scans on the specific channel have to be performed, before switching to the other channels? In the event loop there is an event called SYSTEM_EVENT_SCAN_DONE. I guess this event occurs when the hole of all scan was performed? Is it possible to get information, when one single channel will be switched during wifi scan, e.g. SYSTEM_EVENT_SCAN_NEXT_CHANNEL or SYSTEM_EVENT_FAST_SCAN_FAIL. In my application i repeat the connection process when it was not successful before. But because it would take to much time to wait for a full channel scan to get a result, i just use a hard connection timeout (scan + connect). So to improove connection time it whould help to get information if AP could be found on specific channel as fast as possible.
- After Wifi Scan the Connection takes approx 600-700ms @ 240MHz. This value is very dependend from CPU Clock. Iam not an Expert in Wifi Topics, but i guess the most of the time the ESP does the WPA2 Encryption. I know during light sleep the ESP can maintain the wifi connection. Is it possible to implement a deep sleep mode, where the "wifi encryption" can be stored in flash or RTC RAM? In this case the ESP doesnt has to waste so much energy to establish a new connection.
Ist not hard to guess, that my application is battery driven. At the moment i can run the system with 2 Alkaline batterys for approx 2 years with a connection every 15 minutes. So every shortening of connection time will help to save more energy. I know that WiFi is not an energy optimized wireless technology, but it is still a very good result in comarison to other wireless technologys. And we have a good reason for doing this with Wifi.
Kind regards
BakerMan
Wifi Fast Scan on specific channel only // Save WiFi Encryption on Flash during Deep Sleep
Re: Wifi Fast Scan on specific channel only // Save WiFi Encryption on Flash during Deep Sleep
Hello Again,
i made further tests.
As i supposed, it seems a bit like the ESP32 is doing a "full" Wifi-Scan during esp_wifi_connect(), when the specific AP could not be found on a specific channel during Wifi-Fast-Scan. I dont know if this is expected behavior for Wifi-Fast-Scan. The only thing i see in my current monitor is that ESP32 repeats the active scan procedure every 130ms many times until my connection timeout occurs.
The AP never changes its Wifi-Channel in my application, so the reason for not find it could not be "bad" wifi conditions or the AP is busy (pretty unlikely). Like in my post before i hereby ask, if there is a possibility to change that behaviour? Is there any option to let me know that the AP could not be found on specific channel. Scanning on other channels makes no sense in that application and uses more energy than needed.
I think i could rewirte my code so that he scans on specific channel before connect like this:
1) esp_wifi_scan_start() on specific channel with time limitation e.g. 130ms
2) look if desired AP is on the list; if not return to step 1
3) wifi connect
Please let me know if there is stil an other option.
At last i have a question about the crypto. As far as i know there are two kinds of crypto functions for ESP32, the original and the fast (hardware optimized). Can i use the hardware accelerated one for wifi connect? How do i do that?
Kind regards
BakerMan
i made further tests.
As i supposed, it seems a bit like the ESP32 is doing a "full" Wifi-Scan during esp_wifi_connect(), when the specific AP could not be found on a specific channel during Wifi-Fast-Scan. I dont know if this is expected behavior for Wifi-Fast-Scan. The only thing i see in my current monitor is that ESP32 repeats the active scan procedure every 130ms many times until my connection timeout occurs.
The AP never changes its Wifi-Channel in my application, so the reason for not find it could not be "bad" wifi conditions or the AP is busy (pretty unlikely). Like in my post before i hereby ask, if there is a possibility to change that behaviour? Is there any option to let me know that the AP could not be found on specific channel. Scanning on other channels makes no sense in that application and uses more energy than needed.
I think i could rewirte my code so that he scans on specific channel before connect like this:
1) esp_wifi_scan_start() on specific channel with time limitation e.g. 130ms
2) look if desired AP is on the list; if not return to step 1
3) wifi connect
Please let me know if there is stil an other option.
At last i have a question about the crypto. As far as i know there are two kinds of crypto functions for ESP32, the original and the fast (hardware optimized). Can i use the hardware accelerated one for wifi connect? How do i do that?
Kind regards
BakerMan
Re: Wifi Fast Scan on specific channel only // Save WiFi Encryption on Flash during Deep Sleep
I have a very similar project to you and I'm having a terrible time with WPA2 connection speed. Even if I set the channel, it seems to have these unexplained 'windows' where it can connect. These are, approximately: 1100-1250ms, 2200-2300ms, and occasionally above that with the same increasing interval. eg. It *never* connects after 800ms, or 1500ms, or any other time not in these windows. CPU frequency has little effect (the timing changes of course as the handshake time is altered, but the ~1s delay between connection possibilities remains), WEP connects very quickly with no problems but I prefer better security, router beacon interval has little effect, etc. If anyone has input on that, I'm all ears. I'm curious if you have noticed the same thing with your network? Is your connection time consistent?
Anyway, back to your topic. It gave me the idea to set up a custom 'country' to constrain the WiFi channel. I just tested it and it did nothing to solve my problem but it sounds like it might be useful for you...
See here for docs:
https://docs.espressif.com/projects/esp ... untry-code
eg.
wifi_country_t myWiFi;
Country code (cc) set to 'X','X','X' is the standard, apparently.
chan = the last known/expected channel
nchan = 1 (limit to just this 1 channel)
policy = WIFI_COUNTRY_POLICY_MANUAL;
esp_wifi_set_country(&myWiFi);
Then, because it's limited to the one channel, you can listen for the SYSTEM_EVENT_STA_DISCONNECTED event with reason NO_AP_FOUND (I guess your timeout would be your router beacon interval, plus a little wiggle room? If it doesn't fire in that time, assume it has found and is connecting.).
Anyway, back to your topic. It gave me the idea to set up a custom 'country' to constrain the WiFi channel. I just tested it and it did nothing to solve my problem but it sounds like it might be useful for you...
See here for docs:
https://docs.espressif.com/projects/esp ... untry-code
eg.
wifi_country_t myWiFi;
Country code (cc) set to 'X','X','X' is the standard, apparently.
chan = the last known/expected channel
nchan = 1 (limit to just this 1 channel)
policy = WIFI_COUNTRY_POLICY_MANUAL;
esp_wifi_set_country(&myWiFi);
Then, because it's limited to the one channel, you can listen for the SYSTEM_EVENT_STA_DISCONNECTED event with reason NO_AP_FOUND (I guess your timeout would be your router beacon interval, plus a little wiggle room? If it doesn't fire in that time, assume it has found and is connecting.).
Who is online
Users browsing this forum: Corand, Heggico, jtroncin21 and 73 guests