Prepare Your Code
A code example for ESP32/ ESP8266 / Arduino boards
ESP32 or ESP8266
Arduino (static provision)

3 simple steps to configure your code:

  1. 2.
    Define Template ID and Device Name on top of your firmware, before any includes
  2. 3.
    Upload this sketch into your test board
Final step: Provision your board via Dynamic Provisioning flow and add it to your account using Blynk app
Example of a code with basic functions that you can use for your test product:
1
#define BLYNK_TEMPLATE_ID ""
2
#define BLYNK_DEVICE_NAME ""
3
4
#define BLYNK_FIRMWARE_VERSION "0.1.0"
5
6
#define BLYNK_PRINT Serial
7
//#define BLYNK_DEBUG
8
9
#define APP_DEBUG
10
11
// Uncomment your board, or configure a custom board in Settings.h
12
//#define USE_WROVER_BOARD
13
14
#include "BlynkEdgent.h"
15
16
void setup()
17
{
18
Serial.begin(115200);
19
delay(100);
20
21
BlynkEdgent.begin();
22
}
23
24
void loop() {
25
BlynkEdgent.run();
26
}
Copied!
Instructions and code for Static AuthToken is used when you are working with hardware that doesn't support Blynk.Edgent WiFi provisioning. For example when you are using Ethernet shield, or work with hardware that connects to the Internet over cellular (3G, LTE, etc) network.
  1. 1.
    Download the latest release of Blynk.Edgent as a Source code .zip file
  2. 2.
    Open Arduino IDE
  3. 3.
    In Arduino IDE menu go to Sketch - > Include Library
  4. 4.
    Select Add .ZIP library
  1. 1.
    Select the downloaded .zip archive. Press Choose to continue.
  2. 2.
    After that, you should see Blynk folder under the File > Examples
  3. 3.
    Select the example for the hardware you use. We will use the one for Arduino UNO + Ethernet shield
1
#define BLYNK_PRINT Serial
2
3
/* Fill-in your Template ID (only if using blynk.cloud) */
4
#define BLYNK_TEMPLATE_ID ""
5
#define BLYNK_DEVICE_NAME ""
6
7
#include <SPI.h>
8
#include <Ethernet.h>
9
#include <BlynkSimpleEthernet.h>
10
11
char auth[] = "YourAuthToken";
12
13
void setup()
14
{
15
Serial.begin(9600);
16
Blynk.begin(auth);
17
}
18
19
void loop()
20
{
21
Blynk.run();
22
}
Copied!
Pay attention to these 3 lines: you would need to fill them.
1
...
2
#define BLYNK_TEMPLATE_ID ""
3
#define BLYNK_DEVICE_NAME ""
4
...
5
char auth[] = "YourAuthToken";
6
...
Copied!

Getting Template ID and Auth Token for device

Template ID and Device Name

  1. 1.
    Log in to your Blynk.Console developer account
  2. 2.
    If you don't have a Device Templates -> Create New Template or open an existing one
  3. 3.
    Copy the contents of this section and paste them on top of your firmware, before any includes

Getting Auth Token

When the Template is ready, go to Search -> Devices - Create new device
  1. 1.
    Choose a Template and give your new device a name
  1. 1.
    After the device was created, open its dashboard, go to the Device Info tab. There you will find a field: Auth Token.
Now you have all the information you need to update your sketch:
1
#define BLYNK_PRINT Serial
2
3
/* Fill-in your Template ID (only if using blynk.cloud) */
4
#define BLYNK_TEMPLATE_ID "TMPLbu8YYym5"
5
#define BLYNK_DEVICE_NAME "My First Device"
6
7
#include <SPI.h>
8
#include <Ethernet.h>
9
#include <BlynkSimpleEthernet.h>
10
11
char auth[] = "••••••••••••••VoFvaUOH2U_sI";
12
13
void setup()
14
{
15
Serial.begin(9600);
16
Blynk.begin(auth);
17
}
18
19
void loop()
20
{
21
Blynk.run();
22
}
Copied!
  1. 1.
    Upload the sketch to your device
  2. 2.
    Open Serial Monitor. Wait until you see something like this:
1
Blynk v.X.X.X
2
Your IP is 192.168.0.11
3
Connecting...
4
Blynk connected!
Copied!
Last modified 4mo ago
Copy link