ESP32 / ESP8266 - Configure Client WIFI From AP Web Server

by moro18391 in Circuits > Arduino

404 Views, 2 Favorites, 0 Comments

ESP32 / ESP8266 - Configure Client WIFI From AP Web Server

64be636a65afc0d04eca19ed_esp32.png

The ESP32 and ESP8266 boards are powerful microcontrollers with WiFi connectivity. They are mainly used in the world of home automation and IoT systems thanks to their simplicity.

In this project I want to share a code on Arduino that allows WiFi (Client) configuration via an AP (Access Point).

This need arises from some problems encountered on some home automation controls created for friends and relatives..

The Arduino code is generic and only implements the WiFi configuration, further additional code will be added by you according to your needs.

Supplies

For the following project we will need the following materials:

  • ESP32 or ESP8266
  • 1x Button (for Reset)

Arduino libraries:

Setup of ESP Boards

To install ESP boards:

Open Arduino > File > Preferences find "Additional Boards Manager URLs" and open this window

For ESP32 Enter the following URLs:

https://dl.espressif.com/dl/package_esp32_index.json

For ESP8266 Enter the following URLs:

https://arduino.esp8266.com/stable/package_esp8266com_index.json

..it is possible to add multiple URLs by dividing them by a comma. ","


Close and reopen Arduino > Tools > Board > Boards Manager..


In the top bar search for "esp32" for ESP32 or "esp8266" for ESP8266 and install the boards kit


Program the Boards

To program the board follow the steps below:

> Connect the board via USB to the PC

Arduino > Tools > Board > ESP32 or ESP8266 and select your board

The rest of the programming remains as a common Arduino board.

Then select the USB port and load the program.


Download the following files and place them in a folder named: ESP_AP_WIFI

It is recommended that the two files ESP_AP_WIFI.ino and WiFiSetup.h are both contained in the folder

Guide / How Does It Work

When programming for the first time, you must reset the credentials using the button defined as P_RESET.

It is possible to change the pin where to connect the button. The connection is made between GND and the chosen pin, as the pin is set internally with pullup.

Once the P_RESET button has been pressed, the module must be restarted, de-energizing the board.

At the next startup it will go into configuration mode enabling the access point

Then connect to wifi "ESP_CONFIG" with password "12345678" (credentials can be changed)

Access the IP with a browser: http://192.168.4.1 (the IP is changeable but it is recommended to keep this)

Fill in your wifi credentials and press the "send" button

In this way the ESP will save the credentials, automatically restart and connect to WiFi.

The whole procedure can be followed on the Arduino Serial Monitor


I tried to keep void main and loop as empty as possible for your codes