WiFi provisioning
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)
    Open Arduino IDE
    After that, you should see Blynk folder under the File > Examples
    Select Blynk.Edgent > Edgent_ESP32
In the sketch variables BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME are empty. They should be replaced with the ones from your template. Read below on where to find them.
    Log in to your Blynk.Console developer account
    Go to Templates -> Create New Template or open existing template
    Copy the Firmare Configuration code lines
    Go back to your sketch and replace the configuration lines with what you copied.
Press Upload button to flash the code to your device. If the upload process wend successfully you should see output in the serial monitor:
Now your device is ready to be activated using Blynk app.

Activating device using Blynk app

    Open Blynk App
    Open the MENU icon in the upper right corner In the upper right corner
    Tap on +Add New Device
    App will scan the WiFi networks around you and offer to connect to your device. In our example, device name will be: Blynk Root Template-FAD8F
    Once the connection is established, the Blynk app will guide you through the provisioning process.
When the process if over, you will be prompted to name the device. At this stage, the device is ready to use.
Here is an example of how it works in the app:
For debugging and troubleshooting check the serial monitor output. There you will see how provisioning process is happening on the device.


ESP32/ESP8266-specific issues

If you cannot configure the device, and the log displays AP IP: , please ensure you're using the latest stable Arduino Core version (i.e., not an outdated, beta, or rc version).
In some rare cases it could be a hardware issue of a specific module, so if you have any issues please also try using a new (unused) module.
Last modified 1mo ago