Esp32 cant connect wifi but can connect hotspot

I have 5 ESP32-WROOM-32D model esp32 devices. Two of them connect and work perfectly fine on my own Wi-Fi network. I'm testing them individually, not all at once. However, three of them cannot connect to my home Wi-Fi network, but they can connect to my hotspot network. Both Wi-Fi networks operate at 2.4GHz.

Here are the details of my home network:
ssid = "TP5"
pass="123123Dyg+"

I've set my phone's hotspot settings to the same ssid and password for debugging purposes can connect also , but it couldn't connect to my home Wi-Fi network.

WiFi.status() constantly returns 0.g.

   WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(1000);
  WiFi.mode(WIFI_STA);
  delay(500);
  


  WiFi.begin(ssid, pass);
  Serial.println(ssid);
  Serial.println(pass);

  static int connectionCount = 0;
  //Serial.println("\nConnecting...",ssid,pass);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    setLedColor(LED_RED_COLOR);
   // WiFi.mode (WIFI_AP_STA);
    Serial.println("Connecting to WiFi..");
    connectionCount++;
    if (Serial.available() > 0) {
      processCommand("command");
    }
    else{
      if(connectionCount > 8){
        connectionCount = 0;
        delay(100);
        ESP.restart();
        break;

      }
    }
  }
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Wifi Connection not found");
    return false;
  }
  Serial.println("Connected to the WiFi network");
  connectionCount = 0;

  //setLedColor(LED_GREEN_COLOR);


  return true;
}
kodu buraya yazın veya yapıştırın

Sometime I see some of my esp's taking up to about 10 seconds to connect..
You reboot after about 4, try increasing connectionCount to like 20..

good luck.. ~q

I try with 20,30,40 but this is not working :confused:

strange..

what does this do??

 while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    setLedColor(LED_RED_COLOR);
   // WiFi.mode (WIFI_AP_STA);
    Serial.println("Connecting to WiFi..");
    connectionCount++;
    if (Serial.available() > 0) {
      processCommand("command");
    }
    else{
      if(connectionCount > 30){
        connectionCount = 0;
        WiFi.disconnect();
        delay(100);
        WiFi.begin(ssid,pass);
       // ESP.restart();
       // break;

      }
    }
  }

did you try the WiFi scan demo to see if you even see the net??
under tools - can you increase "Core debug level"??

good luck.. ~q

I moved your topic to a more appropriate forum category @duyci.

The Nano ESP32 category you chose is only used for discussions directly related to the Arduino Nano ESP32 board.

In the future, please take the time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose.

Thanks in advance for your cooperation.

I had similar problems with connecting with the main Wifi network, I worked on a project last year and connected all the ESP 8266 modules to the laptop hotspot which was then connected to the main Wifi. The project worked perfectly. If you are having issues I recommend to type in the 192.168.1.1 IP on your Browser to access the Main Router settings, but you will need to know the password, you will most likely get the password to your network on the packaging of the Router

I've had a similar problem with ESP32 superminis which were very reluctant to connect to my Wifi network.
I solved it based on this: c++ - ESP32 WiFi.status() always returns WL_DICSONNECTED (STA_MODE) - Stack Overflow . In principle you use the function WiFi.waitForConnectResult() as illustrated below:

  // set up wlan
  Serial.println("Starting/Restarting WiFi") ;
  WiFi.mode(WIFI_STA);

  WiFi.begin(ssid, pass);
  Serial.println( "WiFi.waitForConnectResult() . . ." ) ;

  uint8_t status = WiFi.waitForConnectResult();
  while ( status != WL_CONNECTED   ) {
    delay ( 1000 );
    Serial.print ( "." );
    WiFi.begin(ssid, pass);
    status = WiFi.waitForConnectResult();
  }

I didn't change anything, when I tried it the next day it connected to the wifi network. I wonder if the MAC address was temporarily banned by the wifi network?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.