Sending WiFi credentials and and Auth Token to your device
Remember going to the coffee shop and asking for a name and password for their WiFi network to connect your smartphone or laptop to? A familiar situation, right?
Now imagine your ESP32 wants to connect to the Internet. It would also need the name and password of your home or office WiFi. Good for you, Blynk can do all the heavy work.
A complete WiFi provisioning solution from Blynk includes both a firmware code and a mobile app UI to guide you through the WiFi set up. It's called Blynk.Inject
Currently, WiFi provisioning with Blynk.Inject only works on ESP32, ESP8266, WiO Terminal by Seeed, Arduino MKR1010, Arduino Nano 33IoT, and Texas Instruments CC3220.
Raspberry Pi will be supported soon.
How WiFi provisioning works
You can skip this part as this is something you don't have to think about because Blynk does everything for you. But it might be helpful to understand how it works under the hood
In the beginning, your hardware will act as an Access Point (AP). It means that your device will broadcast its own WiFi network with an SSID (name) similar to Blynk Device-1234
Your smartphone will connect to this AP with the Blynk app (or from smartphone settings) and they will start communicating directly with each other
Blynk app will ask you for the name (SSID) and password of the WiFi network you would like to connect this device to
WiFi information (SSID and password) will be sent to the device
Also, Blynk app will request an Auth Token from the server and then send it to the device
Your device will store all of this items in Flash/EEPROM memory
After that, device will automatically reboot. The AP mode will be turned off
Device will use the WiFi credentials you provided to connect to your home or office WiFi network
After the successful authentication, the device is added to your account and ready to use
If you later need to connect to this device to a different network, WiFi credentials can be changed by using Blynk app, by resetting the device with a physical button (you would need to plan it into your electrical circuit design)
Now let's make it work for your devices.
To enhance the user experience it's recommended that you plan these things into your electrical design:
Plan a physical button which will allow resetting the device to its default settings. E.g.: Holding this button for N seconds will erase the AuthToken and WiFi credentials.
Plan an LED to indicate different statuses of device (AP, connected, etc.). It can be RGB or one-color LED.
You can find references to handling reset and statuses indication in Blynk.Edgent examples
Setting up your sketch to enable WiFi Provisioning
Install Blynk Library in Arduino IDE (or download the latest release as a .zip file and install library as a zip file)