ESP SmartConfig 10
From: https://www.techtonions.com/esp32-using-smartconfig/


ESP32 Using SmartConfig Porject Summary About Exp Touch Protocol Prerequisites
Basic WiFi SmartConfig Example Here Is The Example Code How The Code Works setup
Start SmartConfig WiFiConfig With Storage & Rst How Code Works setup
loop writeStringTolash() stringReadFromFlash( int ) Wrapping Up


ESP32 Using SmartConfig
Changing Wi-Fi credentials in code for your ESP32 based IoT project is frustrating, right? As most of us, either hard code Wi-Fi credential or will use famous Wi-Fi manager. Apart from this, there is a method known as ESP-Touch, and it works on SmartConfig technology developed by TI. We will explore SmartConfig technology, and you will be amazed as it is super simple to use and lightweight. We will be using Arduino IDE for programming ESP32.
Project Summary
This tutorial will cover how to use the ESP-Touch protocol with your ESP32 based IoT projects/devices. Using ESP-Touch, you will no longer need to hard code Wi-Fi credentials as you can easily change it whenever you want. We will be using the Espressif app name as EspTouch: SmartConfig for ESP8266, ESP32. By using this app, we can easily configure our ESP32 device with a new Wi-Fi credential. ESP32 using Smart config using ESP-touch app flow chart We will build an ESP32 project to store Wi-Fi credentials in EEPROM memory on a successful configuration. Additionally, we will use the onboard Boot button on ESP32 as a reset button for erasing the stored Wi-Fi credentials and configuring a new one. Here is the Tutorial breakdown: Watch the Video Tutorial This tutorial is available in video format ( watch below ) and written format ( continue reading this page ).
About ESP-Touch Protocol
ESP-Touch protocol uses a SmartConfig technology.  The SmartConfigTM is a technology developed by TI to connect a new Wi-Fi-based IoT device to a Wi-Fi network.  It uses a mobile app to broadcast the network credentials from a smartphone, or a tablet, to an un-provisioned Wi-Fi device. The major advantage of using ESP-Touch is that there is no need to create an Access Point ( AP ) with a known SSID or Password in ESP32. Therefore ESP-Touch protocol provides a seamless way to configure Wi-Fi devices connecting to a router. It is very user-friendly when it comes to headless systems. It only takes few clicks on your smartphone. IoT device is not connected to the network initially, and the ESPTOUCH application cannot send any information to the device directly. With the ESP-TOUCH communication protocol, a device with Wi-Fi access capabilities, such as a smartphone, can send a series of UDP packets to the Wi-Fi Access Point ( AP ), encoding the SSID and password into the Length field of each of these UDP packets. The IoT device can then reach the UDP packets, obtaining and parsing out the required information. As per the ESP-Touch user guide, the data packet structure looks like this.  ESP touch data packet structure for smartconfig And the protocol itself is lightweight compared to the Wi-Fi manager as the Wi-Fi manager requires a webpage code to be stored on device memory.
Prerequisites
We will use Arduino IDE for programming our ESP32 board.  If you are not familiar with Arduino IDE, then you can check our guide on ❑ Getting started with Arduino IDE For programming ESP32 using Arduino IDE, we will need to add the ESP32 board package in Arduino IDE. Follow our guide. ❑ Installing ESP32 in Arduino IDE Skip the above steps if you have already done it before. Additionally, we will need to download an Espressif app name as EspTouch: SmartConfig for ESP8266, ESP32 for Android, or Espressif Esptouch for apple. ESP Touch app download from play store on a android mobile And if you are planning to develop your mobile application, then don’t worry as Espressif has provided all support. Have a look at the following- ESP Touch for Android ESP Touch for IOS ESP Touch support in Flutter  ESP Touch support in React Native
Basic WiFiSmartConfig example
ESP32 package comes with a basic WiFiSmartConfig example for us. Let us understand this example first.  You can navigate to this example at  File > Examples > WiFi > WiFiSmartConfig.  Arduino IDE opening ESP32 SmartConfig example code
Note:- The example path is only visible when selecting the proper ESP32 board in Arduino IDE.

Here is the example code
/*H******************************************************************** * **********************************************************************/ #include "WiFi.h" /*F******************************************************************** * **********************************************************************/ void setup() { Serial.begin( BAUD ); WiFi.mode( WIFI_AP_STA ); // INIT WiFi AS STATION, START SmartConfig WiFi.beginSmartConfig(); Serial.println( "Waiting for SmartConfig." ); while( !WiFi.smartConfigDone() )// WAIT FOR SmartConfig PACKET FROM MOBILE { delay( 500 ); Serial.print( "." ); } Serial.println( "" ); Serial.println( "SmartConfig received." ); Serial.println( "Waiting for WiFi" ); while( WiFi.status() != WL_CONNECTED ) // WAIT FOR AP TO CONNECT TO WiFi { delay( 500 ); Serial.print( "." ); } Serial.println( "WiFi Connected." ); Serial.print( "IP Address: " ); Serial.println( WiFi.localIP() ); } /*F******************************************************************** * **********************************************************************/ void loop() { // PUT YOUR MAIN CODE HERE, TO RUN REPEATEDLY }
Upload this example code on your ESP32 board as we can see there is no hard-coded network credential in the example. ESP32 SmartConfig default example code uploding After uploading, open the serial monitor and set the appropriate baud rate. You will see that it is waiting to be configured by SmartConfig, and it will be showing continuous dots once it enters configuration mode. Arduino IDE serial monitor displays waiting for SamrtConfig configuration Now open the ESP-Touch app in your mobile device and connect your mobile device to your Wi-Fi router network. In android, it will also ask you to turn on location service for detecting the connected Wi-Fi SSID. Android mobile turning on location service and connecting to Wi-Fi It will fetch and display the connected Wi-Fi network SSID and BSSID. Now you need to enter the password of the connected Wi-Fi network. ESP Touch app entering Wi-Fi password and displaying connected network SSID and BSSID Select the Multicast radio button. ESP-Touch app showing connected Wi-Fi SSID and BSSID. And selecting multicast option And press the confirm button, you will see a popup like this. ESP-Touch app shows popup message of configuration Wait for a while, and you will see a success message in the app along with the connected ESP32 BSSID and Inet Address information. ESP-touch app showing success message And, on the serial monitor, you will see a message as SmartConfig received, and now it will be connected to the given Wi-Fi network. Arduino IDE serial monitor showing smartConfig data received and wifi connected It’s that simple, and we do not need any stored SSID or Password for ESP Access Point. The example is not perfect to use right now, as we need to configure it whenever we restart ESP because we are not storing Wi-Fi credentials. Also, ESP will always enter in SmartConfig mode. We will be modifying the existing code to overcome these issues.
How code works
The first step will be to include a required library for the example.