BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

BLYNK_READ is not working always!

Hi All,

I have a very strange problem. I noticed that sometimes I don’t get requests from widget (BLYNK_READ).
For example I have ‘Value Display’ widget with ‘Reading Rate’ = 1 sec.
I use the following source code:

#define BLYNK_DEBUG
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "AUTH_CODE-fvK4W";
char ssid[] = "SSID";
char pass[] = "PASSWORD";

int read_request_counter = 0;
int button_clicks = 0;

BLYNK_READ (V30) 
{
  Serial.println("*** Read request from Blynk ***");
  Blynk.virtualWrite(V30, read_request_counter++);
}

BLYNK_WRITE (V32) 
{
  Serial.println("*** Click Button ***");
  Blynk.virtualWrite(V31, button_clicks++);
}

void setup(void) 
{
  Serial.begin(115200);
  
  while (!Serial) {}
  
  Serial.setDebugOutput(true);
  
  Blynk.begin(auth, ssid, pass);
}

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

I run my hardware (Node MCU v3 Lolin CH340G) and my log from serial monitor:

15:43:46.503 -> scandone
15:43:46.503 -> state: 0 -> 2 (b0)
15:43:46.503 -> state: 2 -> 3 (0)
15:43:46.503 -> state: 3 -> 5 (10)
15:43:46.539 -> add 0
15:43:46.539 -> aid 1
15:43:46.539 -> cnt 
15:43:46.719 -> 
15:43:46.719 -> connected with SSID, channel 3
15:43:46.753 -> dhcp client start...
15:43:46.996 -> ip:192.168.1.48,mask:255.255.255.0,gw:192.168.1.1
15:43:47.177 -> [3568] Connected to WiFi
15:43:47.177 -> [3568] IP: 192.168.1.48
15:43:47.177 -> [3568] 
15:43:47.177 ->     ___  __          __
15:43:47.177 ->    / _ )/ /_ _____  / /__
15:43:47.177 ->   / _  / / // / _ \/  '_/
15:43:47.177 ->  /____/_/\_, /_//_/_/\_\
15:43:47.177 ->         /___/ v0.6.1 on NodeMCU
15:43:47.177 -> 
15:43:47.177 -> [3574] Connecting to blynk-cloud.com:80
15:43:47.210 -> :ref 1
15:43:47.312 -> [3716] <[1D|00|01|00] AUTH_CODE-fvK4W
15:43:47.312 -> :wr 37 0
15:43:47.350 -> :wrc 37 37 0
15:43:47.459 -> :ack 37
15:43:47.459 -> :rn 5
15:43:47.459 -> :c0 1, 5
15:43:47.459 -> [3874] >[00|00|01|00|C8]
15:43:47.459 -> [3874] Ready (ping: 150ms).
15:43:47.459 -> [3874] Free RAM: 48760
15:43:47.493 -> :rn 10
15:43:47.493 -> [3883] >[14|1E]b[00|05]
15:43:47.493 -> :c0 1, 10
15:43:47.493 -> [3886] >vr[00]30
15:43:47.493 -> *** Read request from Blynk ***
15:43:47.565 -> [3953] <[14|1E]b[00|07]vw[00]30[00]0
15:43:47.565 -> :wr 12 0
15:43:47.565 -> :wrc 12 12 0
15:43:47.565 -> [3959] <[11|00|02|00]Hver[00]0.6.1[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]NodeMCU[00]build[00]Apr  9 2020 15:21:14[00]
15:43:47.565 -> :wr 77 0
15:43:47.598 -> :wrc 77 77 0
15:43:47.745 -> :ack 12
15:43:47.889 -> :ack 77
15:43:47.889 -> :rn 5
15:43:47.889 -> :c0 1, 5
15:43:47.889 -> [4302] >[00|00|02|00|C8]
15:43:48.497 -> :rn 10
15:43:48.497 -> [4893] >[14|1E]b[00|05]
15:43:48.497 -> :c0 1, 10
15:43:48.497 -> [4896] >vr[00]30
15:43:48.497 -> *** Read request from Blynk ***

I see ‘Read request from Blynk’ messages… It works as expected.

But then I reboot (or power off -> power on) my hardware and I see the following serial log:

15:44:20.548 -> scandone
15:44:20.548 -> state: 0 -> 2 (b0)
15:44:20.548 -> state: 2 -> 3 (0)
15:44:20.548 -> state: 3 -> 5 (10)
15:44:20.584 -> add 0
15:44:20.584 -> aid 1
15:44:20.584 -> cnt 
15:44:20.794 -> 
15:44:20.794 -> connected with SSID, channel 3
15:44:20.794 -> dhcp client start...
15:44:21.049 -> ip:192.168.1.48,mask:255.255.255.0,gw:192.168.1.1
15:44:21.232 -> [3568] Connected to WiFi
15:44:21.232 -> [3568] IP: 192.168.1.48
15:44:21.232 -> [3568] 
15:44:21.232 ->     ___  __          __
15:44:21.232 ->    / _ )/ /_ _____  / /__
15:44:21.232 ->   / _  / / // / _ \/  '_/
15:44:21.232 ->  /____/_/\_, /_//_/_/\_\
15:44:21.232 ->         /___/ v0.6.1 on NodeMCU
15:44:21.232 -> 
15:44:21.232 -> [3574] Connecting to blynk-cloud.com:80
15:44:21.270 -> :ref 1
15:44:21.377 -> [3711] <[1D|00|01|00] AUTH_CODE-fvK4W
15:44:21.377 -> :wr 37 0
15:44:21.377 -> :wrc 37 37 0
15:44:21.479 -> :ack 37
15:44:21.479 -> :rn 5
15:44:21.479 -> :c0 1, 5
15:44:21.479 -> [3848] >[00|00|01|00|C8]
15:44:21.515 -> [3848] Ready (ping: 130ms).
15:44:21.515 -> [3849] Free RAM: 48760
15:44:21.551 -> [3915] <[11|00|02|00]Hver[00]0.6.1[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]NodeMCU[00]build[00]Apr  9 2020 15:21:14[00]
15:44:21.589 -> :wr 77 0
15:44:21.589 -> :wrc 77 77 0
15:44:21.660 -> :ack 77
15:44:21.660 -> :rn 5
15:44:21.660 -> :c0 1, 5
15:44:21.660 -> [4021] >[00|00|02|00|C8]
15:44:30.582 -> pm open,type:2 0
15:44:31.576 -> [13929] <[06|00|03|00|00]
15:44:31.576 -> :wr 5 0
15:44:31.613 -> :wrc 5 5 0
15:44:31.682 -> :ack 5
15:44:31.682 -> :rn 5
15:44:31.682 -> :c0 1, 5
15:44:31.682 -> [14024] >[00|00|03|00|C8]

From logs you can see that widget doesn’t send any request to V30! but hardware is working, because I can click on button (V32) and I see that counter V31 will increase, see my logs in this moment:

15:44:35.358 -> :rn 12
15:44:35.358 -> [17695] >[14|00|0D|00|07]
15:44:35.358 -> :c0 1, 12
15:44:35.358 -> [17699] >vw[00]32[00]1
15:44:35.358 -> *** Click Button ***
15:44:35.430 -> [17766] <[14|00|0D|00|07]vw[00]31[00]0
15:44:35.430 -> :wr 12 0
15:44:35.430 -> :wrc 12 12 0
15:44:35.499 -> :rn 12
15:44:35.499 -> [17854] >[14|00|0E|00|07]
15:44:35.499 -> :c0 1, 12
15:44:35.499 -> [17857] >vw[00]32[00]0
15:44:35.536 -> *** Click Button ***
15:44:35.572 -> [17924] <[14|00|0E|00|07]vw[00]31[00]1
15:44:35.572 -> :wr 12 0
15:44:35.572 -> :wrc 12 12 0
15:44:35.609 -> :ack 12
15:44:35.750 -> :ack 12

i.e. my program in node mcu is working but for some reasons I don’t get any requests from widget!
If I will reboot hardware again and again I can catch case when it will work again (see my first log).

I tried the same case on other nodemcu device and I saw the same results :frowning:

I tried to create a new test project in Blynk, only for this case, and … it works always! so I think that it is somehow connected specifically with my project, but I want to understand and fix this problem for future projects :slight_smile:

I can send AUTH code for this application, but I’m not sure that I should do it here, i.e. it will be useful for support only.

Details:

  • Node MCU v3 Lolin CH340G (ESP8266 WIFI)
  • I use Android 9.0 (SM-G950FD).
  • Official Blynk server
  • Blynk library v0.6.1

Please, let me know if you need more info from me.

Thanks!

Without more detail on what widgets are connected to which virtual pins, and what function these widgets perform within your app, I’m struggling to understand the logic of what you’re doing here.

Maybe taking a step back and giving an overview, along with details of the widget setup in the app and a summary of where this fits into your final aims for the project will help us point you in the best direction.

Pete.

Thanks for quick response.

Okay, I have the following project:
Three empty tabs and one TEST tab with 3 widgets:

  1. “Read Counter” [value display widget]
    INPUT: V30 (0 … 1023)
    READING RATE: 1 sec

  2. “Counter Btn” [value display widget]
    INPUT: V31 (0 … 1023)
    READING RATE: PUSH

  3. “Click” [button widget]
    OUTPUT: V32 (0 -> 1)
    MODE: PUSH
    LABELS: OFF / ON

My final aim to understand why BLYNK_READ operation is not working (for V30) always and fix this problem.

But what is this used for, what’s the purpose of the app, and the the three widgets?
How does the user interact with this?

Pete.

Okay…

I prepare a simple test application.

We have one “value display” widget (V30), this widget (each second) send REQUEST to hardware, in hardware in “BLYNK_READ (V30)” block we increment value (read_request_counter) and via virtualWrite send updated value.

Then we have button (v32), this widget send request to hardware and we in “BLYNK_WRITE (V32)” block increment value (button_clicks) and via virtualWrite send this updated value to application.

Value display widget (V31) display ‘button_clicks’ value.

Problem that I don’t get requests from “READ COUNTER” (V30) always. I described this problem in more details in first my message.

The reason for asking is that I’ve never found the need to use the BLYNK_READ functionality. I don’t see the purpose in having it in the library, and for me it serves no purpose that can’t be achieved better in other ways.

The one time I did try to use it, to help debug someone’s code, it didn’t work for me. When I commend on this the devs asked me to send them details, and when I tried to reproduce the issue it did work.

Clearly in your test example, the solution would be to run a timer, or use millis()/1000, and send the result to the display widget.
If you wanted a non-volatile capability too then using BLYNK_CONNECTED and Blynk.syncVirtual(V30) to retrieve the existing value would be one solution, although incorporating this with millis()/1000 wouldn’t be the best approach.

Pete.

Thanks Pete for your help.

The reason for asking is that I’ve never found the need to use the BLYNK_READ functionality.

In my case, I don’t want to load processor for sending data via WIFI always. I want to do it only when I open application and it will be great to change the polling frequency for each widget separately (from the application). In this case, it will be very convenient to use BLYNK_READ functionality.

I noticed that each Blynk.virtualWrite operation takes ~ 45ms, so if I have only 10 widgets it will take ~ 0.5 sec only for send information, but I have different sensors and I need to read data from sensors as fast as I can and then process these data, so as I wrote above I don’t want ALWAYS load processor only for sending data.

Yeap I understand, that I can send these statistical data only when I click to special button (I think that, I will use this way, while tech. support will not fix this problem) and I know that I can send them rarely, but I think BLYNK_READ will be useful for me.

When I commend on this the devs asked me to send them details

How can I attract the attention of developers? :thinking:

BLYNK_APP_CONNECTED would be my way to only send data to the app when needed.
Of course of you want to use Superchart to map any of this data then you’d need to be writing it to virtual pins anyway - data is aggregated and averaged over one minute periods, so sending the too frequently has no real benefit.

I’d also look at how often your sensors can reasonably be interrogated, as some sensors like the DHT11 get very unhappy if they are read more frequently than about once every 5 seconds.

Maybe your BLYNK_READ issue is one for @BlynkAndroidDev

Pete.

BLYNK_APP_CONNECTED would be my way to only send data to the app when needed.

Thanks for this, it is useful information! I missed this.

I’d also look at how often your sensors can reasonably be interrogated

It is reflective sensors which include an infrared emitter and phototransistor in a leaded package, I need to monitor distance change to reflective surface as fast as I can in real time.

Maybe your BLYNK_READ issue is one for @BlynkAndroidDev

Thanks