Using WiFi AutoConnect With ESP8266/ESP32 Boards




Introduction: Using WiFi AutoConnect With ESP8266/ESP32 Boards

About: #BnBe is a platform to help teach electronics no matter what the age or skill level. We’re currently designing a wide range of products from beginner level kits to industry-standard microcontroller platforms.

We will learn how to use the AutoConnect library that allows us to connect to and manage WiFi access points using a smartphone.

The video above will guide you through the process along with the various screens that you need to access to learn about the AutoConnect library. This written post will only cover it in brief.

Step 1: Obtain & Upload the Sketch

When the ESP32 board boots, it checks to see if any previous network credentials have been stored in the FLASH. By default, it will try to connect to them and if successful then it will print the IP address to the Serial port. Your sketch will then operate as normal. If it is unable to connect to a WiFi network then it will create an access point that you can connect to and manage the WiFi credentials.

Let’s start by installing the required libraries in the Arduino IDE. We need to install the AutoConnect library. Open up the library manager and type in AutoConnect. Install the library that shows up. The AutoConnect library needs the PageBuilder library for it to function so type in PageBuilder and install that as well. Then, download and open up the sketch for this project.

Link to sketch:

You don’t have to change anything in the sketch but if you want to, then you can assign a different hostname for your board. It’s now time to upload the sketch. Connect the board using the diagram above, open up the serial terminal and press the reset button. You will receive a message indicating that the board is ready to receive code. Hit the upload button and wait for it to complete. Keep the serial terminal open, remove the boot jumper and press the reset button.

At this point, either two things will happen. If previous network information was stored in the flash memory then the board would automatically connect to the network and print out the IP address and hostname. In this case, you do not have to do anything. If you want to erase the stored credentials then you will have to erase the FLASH memory and the video has instructions for you to do this. However, if it was a new board or if there was no valid information then it would create an access point.

Step 2: Connect to AP and Manage WiFi

If the board is unable to connect to a WiFi network then it will create an access point named "esp32ap" and this normally shows up after about 30 seconds. Connect to it by using the default password of 12345678. It should automatically redirect you to the management page or else, you can use the IP address to get to it. The page gives you some information about the board like the MAC address, memory status and so on. The menu gives you a number of options: The ability to configure new access points or networks. View saved SSIDs or networks. Disconnect from the current network. Reset or restart the board. Change the time zone. And also go to the home page which simply displays the time.

Tap the configure new AP option. Select the access point from the list and type in the password. Once done, hit apply and the board should connect to the network and give you the network details as shown in the images. The IP address will also be printed to the serial terminal along with the hostname.

The next time you boot the board, it will automatically connect to a WIFI network and your sketch will work as expected.

Step 3: Deleting WiFi Networks

I have not found a simple way to erase the stored SSID details from the flash by using the management page. One way to do this is by restoring the board to factory defaults by using the esptool which can be used on Windows and Mac. Doing this means that you will have to upload your sketch again. If you’re running Windows then there’s an easier way for you to do this. You can download and install the ESP32 Flash Download tool. The video shows you how to use this tool. The flash download tool does not work for Mac so the only option you have is using the esptool. You will need to install it first by using the terminal and you can then erase the flash by specifying the port. Again, please refer to the video for the commands and how to use them.

Link to sketch:

If you've liked this post, then don't forget to follow us using the links below as we will be building many more projects like this one:

Be the First to Share


    • Build a Tool Contest

      Build a Tool Contest
    • First Time Author Contest

      First Time Author Contest
    • Meatless Challenge

      Meatless Challenge



    27 days ago on Step 3

    Hey man! Thanks for this post! I checked your social media accounts to add ya, but your website or social media dont work.. idk i hope your good. Dont get discouraged! You offered great insight to many gadgets and things! I for one really do appreciate everything youve done. I got to learn how to do it, this whole time i was struggling with the concept. Thanks again!