A method that sets or changes ESP32 WiFi connection without re-programming.

This tutorial shows how to set the ESP32 WiFi connection secondly without re-programing.

In the past, I used to program ESP32 for setting or changing the WiFi. Once the WiFi setting needs to be changed, I will need to re-program the ESP32. When I show my ESP32 project to my audience, the ESP32 was not working because of the WiFi changed, and I must reset the ESP32 by re-programing, troublesome!~

So I want to set or change the ESP32 WiFi connection without re-programming that I have downloaded the program once.

After my research and testing, I found two problems in WiFi Setting without re-programming: how to transmit the WiFi name and password to ESP32; and how to store the information in ESP32.

Transmit wifi setting information

ESP32 has to get the WiFi name and password for connecting to WiFi. In the past, the WiFi information can be in code and programmed to ESP32.


In the new method, the WiFi information can be transmitted from the phone to ESP32.

  • Set the working mode of ESP32 to AP mode that the phone connects it.
  • Set ESP32 to establish the server that the phone can log in to input the WiFi information.

so the ESP32 can obtain the information from the server.


Store setting information

To Keep the WiFi info, the WiFi setting information needs to be store without being affected by the restart of the ESP32. Non-volatile storage (NVS) library is designed to store key-value pairs in flash. The information would be store in the NVS as the key. Now, ESP32 can be connected to the WiFi with the information read from the flash when it re-start.

  • Check the digital pin for setting WiFi. If the setting pin level is low in three seconds, Set the esp32 to work in AP mode:
        void ap_init()
//WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
  • Initiate the server.
        int wifi_config_server()
WiFiClient client = server.available(); // listen for incoming clients
if (client) // if you get a client,
  • If the server responds, the WiFi information can be obtained from the URL of the response.
  • Store the information to ESP32 flash.
        void record_wifi(char *ssid, char *password)
esp_err_t err = nvs_flash_init();
err = nvs_flash_init();
  • Check the data and initiate the WiFi Connection.
        check_wifi(ssid, password);
WiFi.begin(ssid, password);
  • The program has been completed with Arduino. And it is available for the need and can be obtained from https://github.com/Makerfabs/Makerfabs_FAQ/tree/master/Arduino_ESP32/arduino_example/wifi_set_demo. The program has been packaged to a library for ease of use. The using demo is as the following:
        #include "wifi_save.h"
void setup()
Serial.println("Connect WIFI SUCCESS");
Serial.println("Connect WIFI FAULT");
void loop()
  • Open the program by the Arduino ide, upload it to the ESP32 board.
  • Reset the ESP32 board and put the pin(IO21) level to low for starting the WiFi connection.
  • Use the phone to connect the WiFi “makerfabs-ap” build by the esp32.
  • Enter the address “” to log in to the server in the browser. (notice: because of the technical difficulty, the chrome app is recommended to use and the other browsers maybe be not working.)
  • Enter your WiFi information on the browser page.
  • The ESP32 board connects to the WiFi after seconds.
  • If you want to change the WiFi connected, restart the ESP32 and put the IO21 level to low in three minutes. The esp32 will reset the AP mode. You can follow the above steps to change the new WiFi.

You can view the result of the WiFi connection in the serial monitor window when the ESP32 board connected to the PC, also can check the result by the router.


Just after downloading the program, ESP32 can be connected or changed the WiFi without re-uploading the program, which is very convenient for people who have little or no Arduino and programming knowledge to set wifi connection secondly. It is suitable to use in the ESP32 project which will be shared with friends that need to connect to different WiFi.