user80680: I am trying to scan wifi in sta_ap mode in my esp32 wroom 32 module but it is not scanning new wifi .Can anybody tell more about how does wifi mode works in this module and what's the problem in my code.Same code is working in esp8266.
CODE:
#include <WiFi.h>

const char *ap_ssid = "ESP32";
const char *ap_password = "";

const char *sta_ssid = "KKACT"; 
const char *sta_password = "kk25990418";
void setup() {
  Serial.begin(115200);
  
  WiFi.mode(WIFI_AP_STA);
  WiFi.disconnect();
  delay(100);
  Serial.print("Configuring access point...");
  WiFi.softAP(ap_ssid, ap_password);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);

  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(sta_ssid);
  WiFi.begin(sta_ssid, sta_password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
   Serial.println("Now scanning wifi continously");
   int n=WiFi.scanNetworks();
   for (int i = 0; i < n; ++i)
  {
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(WiFi.SSID(i));
      Serial.print(" (");
      Serial.print(WiFi.RSSI(i));
      Serial.print(")");
    
  }
    delay(2000);
}


user1576: This is a issue raised on github about this:
https://github.com/espressif/arduino-esp32/issues/3294
And the issue seems to be that a failed connect prevent the scanning and the solution is:

So what i did was when entering the portal:
WiFi.mode(WIFI_OFF); // otherwise Wifi.Scannetworks() fails
delay(5000);
This seems to stop the processes that prevent the scanning.
After that an immediate scan works without problems.


80680: <p>I am trying to scan wifi in sta_ap mode in my esp32 wroom 32 module but it is not scanning new wifi .Can anybody tell more about how does wifi mode works in this module and what's the problem in my code.Same code is working in esp8266.</p>
<p>CODE:</p>
<pre><code>#include &lt;WiFi.h&gt;

const char *ap_ssid = &quot;ESP32&quot;;
const char *ap_password = &quot;&quot;;

const char *sta_ssid = &quot;KKACT&quot;; 
const char *sta_password = &quot;kk25990418&quot;;
void setup() {
  Serial.begin(115200);
  
  WiFi.mode(WIFI_AP_STA);
  WiFi.disconnect();
  delay(100);
  Serial.print(&quot;Configuring access point...&quot;);
  WiFi.softAP(ap_ssid, ap_password);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print(&quot;AP IP address: &quot;);
  Serial.println(myIP);

  Serial.println();
  Serial.print(&quot;Connecting to &quot;);
  Serial.println(sta_ssid);
  WiFi.begin(sta_ssid, sta_password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(&quot;.&quot;);
  }

  Serial.println(&quot;&quot;);
  Serial.println(&quot;WiFi connected&quot;);
  Serial.println(&quot;IP address: &quot;);
  Serial.println(WiFi.localIP());
}

void loop() {
   Serial.println(&quot;Now scanning wifi continously&quot;);
   int n=WiFi.scanNetworks();
   for (int i = 0; i &lt; n; ++i)
  {
      Serial.print(i + 1);
      Serial.print(&quot;: &quot;);
      Serial.print(WiFi.SSID(i));
      Serial.print(&quot; (&quot;);
      Serial.print(WiFi.RSSI(i));
      Serial.print(&quot;)&quot;);
    
  }
    delay(2000);
}
</code></pre>
 1576: <p>This is a issue raised on github about this:</p>
<p><a href="https://github.com/espressif/arduino-esp32/issues/3294" rel="nofollow noreferrer">https://github.com/espressif/arduino-esp32/issues/3294</a></p>
<p>And the issue seems to be that a failed connect prevent the scanning and the solution is:</p>
<blockquote>
<p>So what i did was when entering the portal:</p>
<p><code>WiFi.mode(WIFI_OFF); // otherwise Wifi.Scannetworks() fails</code></p>
<p><code>delay(5000);</code></p>
<p>This seems to stop the processes that prevent the scanning.</p>
<p>After that an immediate scan works without problems.</p>
</blockquote>
