Adding WiFi with AsyncWiFi Manager

For our ESP32 to connect to our WiFi network it must know both our SSID and password.

The easiest way to do this is to include them in your source code.

There are two big problems with this:

  • moving to a new network requires the source code to be changed, re-compiled, and flashed
  • extra care has to be taken if your code is stored in git! (You want to put your credentials in a seperate file and use .gitignore to make sure they don’t get added to a public git repository.)

To make this a lot easier people have created WiFiManager Captive Portal libraries that turn the ESP32 into it’s own, limited, access point with a setup website.

There are several different WiFiManagers for the ESP32.

We are going to use the [ESPAsync_WiFiManager](https://github.com/khoih-prog/ESPAsync_WiFiManager) as it appears to be the most actively developed at this stage.

It includes several examples, including a double-reset-detector that will re-enable the configuration portal after two presses of the reset button within a configurable amount of time.

Setup

Unfortunately we will need to install Arduino 1.8. as presently Arduino 2.x does not have any support for the file system plugin that we will use to upload the files for the website we’ll be making the ESP32 server.*

1. Install Arduino 1.8.x

It has the circle icon, not the rounded-rectangle icon (version 2.0.)

2. Add the board URLs

Add https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json and http://arduino.esp8266.com/stable/package_esp8266com_index.json to the list of board managers.

Note: these will be shared between Arduino 1.x and 2.x, but it seems we need to add the board definition files to both versions of Arduino.

3. Add the required Libraries

Add these libraries:

  • Adafruit_BME280_Library
  • Adafruit_BusIO
  • Adafruit_GFX_Library
  • Adafruit_SSD1306
  • Adafruit_Unified_Sensor
  • AsyncTCP-master
  • ESPAsyncDNSServer-master
  • ESPAsyncTCP-master
  • ESPAsyncWebServer-master
  • ESPAsync_WiFiManager
  • ESP_DoubleResetDetector
  • TinyGPSPlus

Many can be added via the library manager. But some need to be manually added- eg the dependencies for [ESPAsync_WiFiManager](https://github.com/khoih-prog/ESPAsync_WiFiManager). You will need to go to that page and follow the instructions. This guide for how to manually install libraries is useful.

You will also want to add the enhanced es32fs-plugin for Arduino.

To save time you can also download a prepared zip file from here and unzip it to your Arduino sketch directory.

4. Restart Arduino 1.8!

So that everything that you’ve added is picked up!

Now for the Code!

Download today’s example from https://github.com/MakeItZone/CommunitySensorsHardware/tree/main/Firmware/MIZEnvSensor4-WiFiManager/MIZEnvSensor4-WiFiManager.

Open it in Arduino 1.8.x.

Set your board type to be: ESP32 Wrover Module.

Read through the code and try and get a feel for what it is doing.

Make sure to change the prefix for the access point name that it will create. And change the default access point password to something you will remember!

Program it, and then enable the serial console- set the baud rate to 115200.

Watch the messages and experiment with double taping the reset button.

Use a phone or tablet and connect to your devices SSID. You should be automatically directed to a configuration web site.

Explore the configuration pages.

Add an existing WiFi access point and see what happens!

Extra

Start working on the To do’s in the main loop() function.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top