Page 1 of 2

WiFi station no longer finds APs after 5 minutes of scanning

Posted: Thu Mar 07, 2024 6:15 pm
by stonehouse
Hello everyone,

I am currently working on an application for the ESP32S2 in which a WiFi station searches for APs whose SSID starts with a certain prefix. The station should search until it finds such an AP. I have a log running in the background. From this I can conclude the following:
The station always finds APs in the vicinity for around 5 minutes. However, it does not connect to any of them because the SSIDs of the APs do not start with the correct prefix (this was intended to test the behavior of the station). However, after 5 minutes of searching, the station can no longer find a single AP in the vicinity, even though I know that the same APs are still available.
Does anyone have a similar problem?

Best regards,
Louis

Re: WiFi station no longer finds APs after 5 minutes of scanning

Posted: Fri Mar 08, 2024 11:43 am
by chegewara
You should check if you dont have memory leak in code.
When there is no free ram wifi wont work.

Re: WiFi station no longer finds APs after 5 minutes of scanning

Posted: Fri Mar 08, 2024 12:34 pm
by stonehouse
Thank you for your answer. I don't think it's a memory leak, I've already doubled the available memory for the task and checked to see if it changes anything about the time. The scanning does not stop after the 5 minutes, I can see that in the log. The ESP keeps scanning, but the WiFi stack tells me that there are 0 APs in the vicinity.

Re: WiFi station no longer finds APs after 5 minutes of scanning

Posted: Fri Mar 08, 2024 1:08 pm
by RalphD
I barely remember something that by error if the station does not find any AP after 10 attempts it stops searching. Each attempt is logged and final a log is fired saying that after 10 attempts without result it stops searching

May be that helps, just bean an issue for me like a year ago

Re: WiFi station no longer finds APs after 5 minutes of scanning

Posted: Mon Mar 11, 2024 10:38 am
by stonehouse
I added to the code that the ESP should restart if it detects 0 APs 20 times in a row. I let the log run on the side so that I can see how many scans the ESP performs until it finds no more APs. This is the result:

Number of WiFi scans in area 1: 120
Number of WiFi scans in area 2: 109
Number of WiFi scans in area 3: 108
Number of WiFi scans in area 4: 107
Number of WiFi scans in area 5: 114
Number of WiFi scans in area 6: 115
Number of WiFi scans in area 7: 117
Number of WiFi scans in area 8: 112

So it always seems to happen after a similar time. However, it is not always the same value.

Re: WiFi station no longer finds APs after 5 minutes of scanning

Posted: Mon Mar 11, 2024 11:44 am
by boarchuz
You want to rule out a memory leak exhausting heap memory, not your task's stack.

Log these after each scan: esp_get_free_heap_size(), esp_get_minimum_free_heap_size()

Re: WiFi station no longer finds APs after 5 minutes of scanning

Posted: Mon Mar 11, 2024 12:47 pm
by stonehouse
Thank you, I have found the mistake. For whatever reason, I had used a malloc for the AP list during the scan, but forgot to release the memory again (classic). I have now removed all mallocs from the code

Re: WiFi station no longer finds APs after 5 minutes of scanning

Posted: Mon Mar 11, 2024 12:51 pm
by RalphD
well then please we spend the time to help you so you spend the time to tell what the cause was !!!!

Re: WiFi station no longer finds APs after 5 minutes of scanning

Posted: Mon Mar 11, 2024 1:03 pm
by stonehouse
See my last post

Re: WiFi station no longer finds APs after 5 minutes of scanning

Posted: Mon Mar 11, 2024 1:35 pm
by chegewara
stonehouse wrote:
Mon Mar 11, 2024 12:47 pm
Thank you, I have found the mistake. For whatever reason, I had used a malloc for the AP list during the scan, but forgot to release the memory again (classic). I have now removed all mallocs from the code
Yes, its classic. Everyone been there, including me, thats why my previous response


Good you found the issue