Wifi Fast Scan on specific channel only // Save WiFi Encryption on Flash during Deep Sleep
Posted: Wed Jan 23, 2019 1:15 pm
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
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