Skip to content

blynk

Environment

  • ESP32 DevKit C
  • Macbook Pro
  • iphone
  • Wifi
  1. Download Blynk App
    • Sign up
    • Confirm email address and get credential
    • Create new project
      • choose “ESP32 Dev Board”
  2. Install blynk library
    • for Arduino IDE, install it at Tools > Manage libraries : Blynk by Volodymyr Shumanskyy Version 1.0.0-beta.3
    • Go to Blynk code builder
      • Choose hardware: choose “ESP32 Dev Board”
      • Choose connectivity type: “Wifi”
      • Add auth token (received by email)
      • Copy /examples/Boards_WiFi/ESP32_WiFi/ESP32_WiFi.ino
      • Paste code to Arduino IDE
      • Set Auth token, SSID, password
    • Flash and play
      • Upload sketch to ESP32
    • On serial monitor, you will see
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      [33] Connecting to HM-G24
      [615] Connected to WiFi
      [615] IP: 192.168.0.17
      [615] 
          ___  __          __
        / _ )/ /_ _____  / /__
        / _  / / // / _ \/  '_/
      /____/_/\_, /_//_/_/\_\
              /___/ v1.0.0-beta.3 on ESP32
      
      [692] Connecting to blynk-cloud.com:80
      [1418] Ready (ping: 409ms).
      
  3. Connect hardware Pinmap

    ESP32 devices
    25 Resister470Ω - LED(a)
    GND LED(c)
  4. Configure app

    • Add button
    • Assign hardware Pin : GP25
    • value : 0 - 1

    blynk_blink

Then it worked !

Ref.


Consideration to use Brynk

Timer

delay() in loop() should NOT be used as this blocks Brink.run() that keeps Board connection to cloud. Instead, using BlynkTimer like below works.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
BlynkTimer timer; // Announcing the timer

void setup()
{
  timer.setInterval(1000L, sensorDataSend); //timer will run every sec 
}

void sensorDataSend()
{
  sensorValue = analogRead(A5);
  Blynk.virtualWrite(V1, sensorValue);  // sending sensor value to Blynk app
}

void loop()
{
  Blynk.run();        // run Blynk magic
  timer.run();        // run timer every second
}`

Ref. Keep your board clean

Virtual pins

Virtual pins allow you to interface with any sensor, any library, any actuator.

To read the data from app,

1
2
3
4
BLYNK_WRITE(V5) // V5 is the number of Virtual Pin  
{
  int pinValue = param.asInt();
}
  • Virtual pins have no physical properties.
  • Don’t place Blynk.virtualWrite(V5) inside void loop()

Ref.What is virtual pins


Display sensor data in Blynk app

Error

This did NOT work for analogRead() on ESP32 dev module (2021.05.08)

There are two major ways of displaying sensor data in the app:

  • PULL. In this case, Blynk app will request the data only when the app is open;

  • PUSH. In this case your hardware will be constantly sending data to the Blynk Cloud. And when you open the app, it will be there waiting;


PULL

PULL sensor data when Blynk app is running over Virtual Pins.

Installation

In Blynk app:

  1. Create a New Project (new Auth Token will be sent to your email);
  2. Add Value Display Widget;
  3. Go to Widget Settings ;
  4. Set PIN to Virtual Pin V5;
  5. Set Frequency to 2 seconds;

blynk_blink

Preparing code:

  1. Open this example sketch. Changed machine to ESP32
  2. Insert your Auth Token(received by email), Wifi SSID and password in the sketch;
  3. ⚡️ Flash the code to your hardware;
  4. In the Blynk app - press Play button;
  5. You should see the data coming;

Source code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxx";
char pass[] = "xxxxxxxxxx";

#define VOLUME_PIN 4
// Use Virtual pin 5 for uptime display
#define PIN_UPTIME V5

int sensorData = 0;

// This function tells Arduino what to do if there is a Widget
// which is requesting data for Virtual Pin (5)
BLYNK_READ(PIN_UPTIME)
{
  // This command writes Arduino's uptime in seconds to Virtual Pin (5)
  sensorData = map(analogRead(VOLUME_PIN), 0, 4096, 0, 255);
  Blynk.virtualWrite(PIN_UPTIME, sensorData);
}

void setup()
{
  pinMode(VOLUME_PIN, INPUT);
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}

void loop()
{
  Blynk.run();
}

Pinmap

ESP32 devices
4 Potentiometer datapin
5V Potentiometer VCC
GND Potentiometer GND

Outcome

At this point, I only could retrieve static data (max value) even I waited over 2 - 15 minutes

blynk-pull


PUSH

PUSH. Send sensor data from hardware in intervals over Virtual Pins

consideration

  • VERY IMPORTANT: You can’t send sensor data in your void loop()
    • because calling it in loop() cause flood of data
    • when Blynk Cloud notices that, it automatically ✂︎ cuts your connection.
    • using BlinkTimer instead.

Installation

In Blynk app:

  1. Create a New Project (new Auth Token will be sent to your email)
  2. Add Value Display Widget
  3. Go to Widget Settings
  4. Set PIN to V5
  5. Set Frequency to PUSH

blynk_blink

Preparing code:

  1. Open this example sketch.
  2. Check your email inbox for Auth Token; Insert your Auth Token(received by email), Wifi SSID and password in the sketch;
  3. ⚡️ Flash the code to your hardware;
  4. In the Blynk app - press Play button;
  5. You should see the data coming;

Source code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// #define VOLUME_PIN A10
#define VOLUME_PIN 27


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxx";
char pass[] = "xxxxxxxxxxx";

// int sensorData = 0;

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.

  // Blynk.virtualWrite(V5, millis() / 1000);

  int sensorData = analogRead(VOLUME_PIN);
  Blynk.virtualWrite(V5, sensorData);
}

void setup()
{
//  pinMode(VOLUME_PIN, INPUT);

  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

Pinmap

same as “PULL” case

outcome

I only could retrieve static data (max value - 4095) (same as “PULL” case)

Even I tried follows, it did not work for analogRead()

  • define A10 (set ADC Pin)
  • tried to use the other pin : GPIO27
  • make sensorData parameter as local variable

When keeping Blynk.virtualWrite(V5, millis() / 1000); in myTimerEvent, it sends changing value to Blynk app.

It looks a few people faces same thing


References


Last update: May 8, 2021