• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

ESP-32 intermittent failure to connect to WiFi – SOLVED

Q&A Forum › Category: ESP32 › ESP-32 intermittent failure to connect to WiFi – SOLVED
0 Vote Up Vote Down
Tom Wilson asked 2 years ago

After a month of trying various alternatives, I finally solved my ESP-32 intermittent WiFi connection problem.  I have an application that uses a BME280 to send weather data to a webserver every 5 minutes, and then sleeps until the next period.  About 10% of the time it would not connect to my WiFi despite having a strong signal.  I replaced the typical connection code from numerous examples with the code below and it now connects every time.  Sometimes I get the “WiFi failed” message once but then it connects immediately after. I hope others may find this helpful.
 

Serial.println(“Connecting”);
  while(1) {
      delay(2000);
      WiFi.begin(ssid, password);
      if(WiFi.waitForConnectResult() == WL_CONNECTED) break;
      else Serial.println(“WiFi Failed”);
  }
  Serial.println(“”);
  Serial.print(“Connected to WiFi network with IP Address: “);
  Serial.println(WiFi.localIP());
  long rssi = WiFi.RSSI();
  Serial.print(“RSSI:”);
  Serial.println(rssi);

Question Tags: WiFi Connection
5 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
Thank you so much for sharing that code snipet.
I will recommend it to anyone having connection problems similar to yours.
Thank you.
Regards,
Sara

0 Vote Up Vote Down
Tom Wilson answered 2 years ago

My pleasure!  Here is the website I was working on – https://jobohoa.com/weather.  It is a set of weather gauges for my homeowners association in Costa Rica.  It borrows heavily from the code examples and teachings in your tutorials and uses mySQL, PHP, Javascript, HTML, CSS, and ESP32 C++ running on an Unexpected Makers Feather S3 and a LightSail server instance on AWS.  Your tutorials and books are great!  

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Your website looks great!
I’m glad our tutorials were useful.
Thank you so much for your support.
Regards,
Sara

0 Vote Up Vote Down
LoetLuemmel answered 2 years ago

Thanks for sharing these bytes!
I have a similar issue with a free WiFi Hotspot and will also try your solution.
It looks like the current code just worries once about getting connected, but in case of failure no reconnect takes place (my assumption).
Here I need a solution with more endurance and hopefully your approach makes the difference,

Thanks again and happy coding,
Loetluemmel!

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
You can also try taking a look at Wi-Fi events.
You can create an event that listens for a disconnection and tries to reconnect.
Here’s a link to the tutorials: 

  • https://randomnerdtutorials.com/esp32-useful-wi-fi-functions-arduino/
  • https://randomnerdtutorials.com/solved-reconnect-esp32-to-wifi/

I hope this also helps.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.