Programatically call V numbers

I can’t believe this question hasn’t been asked loads of times before. I’ve searched and found nothing.
Ss it possible to substitute the V number with a variable so that one can call one of many widgets by setting the variable?

Yes. The leading “V” is optional, so you can do…

Blynk.virtualWrite(V1,value);

Blynk.virtualWrite(1,value);

int myPin = 1;
Blynk.virtualWrite(myPin,value);

and they all produce the same result.

Just be careful, if you put this into a loop, that you don’t exceed more than 1 virtualWrite every 0.1 seconds otherwise you maty run into server flooding issues.

The other potentially useful tool is BLYNK_WRITE_DEFAULT(), which saves having to have multiple BLYNK_WRITE(vPin) callbacks in the same sketch.

BLYNK_WRITE_DEFAULT()
{
  int widget_pin = request.pin;      // Which virtual pin triggered this BLYNK_WRITE_DEFAULT callback?
  int widget_value = param.asInt();  // Get the value from the virtual pin (0 = off, 1 = on)
}

Juist be aware that this only works with virtual pin numbers of 0-127.

Pete.

Dear Pete,
I not sure is there any topic talking about calling multiple .setProperty and virtualWrite.
Blynk.setProperty
Blynk.virtualWrite

in my ESP32 code i have 10 tags to read by Blynk.
when i have only 1 tag, it works fine,
when i have more tags say 10 tags, seems like it will take more esp’s resources and slow down the response of esp for other purposes.
Any work around at Blynk commands?
Or i need to have different core to handle Blynk’s virtualWrite?

Hi Simon,
I don’t understand your question I’m afraid.
Maybe you should post your working “one tag” code and explain how you’d like to expand that, and what you’ve tried that didn’t work.

Pete.

Dear Pete,
Well i taking some time to reply to you… below is the ESP32 code, in a function:
With V1 and V2 only, it work fine. But if i uncomment all of the V3 to V10, the esp32 will slow down extremely. I am sure there is work around, right? Thanks in advance.

[Unformatted code removed by moderator]

@Simon_Cheng please edit your post and add triple backticks at the beginning and end of your code snippets so that they display correctly.

Triple backticks look like this:
```

Pete.

void funcTion()
{

 Blynk.setProperty(V1, "label", "Car Speed");
 Blynk.virtualWrite(1, carSpeed);

Blynk.setProperty(V2, "label", "DL Distance Traveled");
Blynk.virtualWrite(2, carDistance);

//  Blynk.setProperty(V3, "label", "SOS-Distance Limiter");
//  Blynk.virtualWrite(3, SOS);

//  Blynk.setProperty(V4, "label", "DL Active");
//  Blynk.virtualWrite(4, DLActive);

//  Blynk.setProperty(V5, "label", "Reset");
//  Blynk.virtualWrite(5, AppReset);

//  Blynk.setProperty(V6, "label", "Engine ON");
//  Blynk.virtualWrite(6, engineON);

//  Blynk.setProperty(V7, "label", "All Door Closed");
//  Blynk.virtualWrite(7, AllDoorClosed);

//  Blynk.setProperty(V8, "label", "Mode");
//  Blynk.virtualWrite(8, SysMode);

//  Blynk.setProperty(V9, "label", "Immobilized");
//  Blynk.virtualWrite(9, stopEngineF);

//  Blynk.setProperty(V10, "label", "chipId");
//  Blynk.virtualWrite(10, chipId);
 
}

the above code (if uncomment all) will takes more than a second, it will cause the esp32 “hung” for more than a second.
Any work around on such code?

I’d asked you to edit your previous post, not leave the unformatted code hanging there and re-post the code in a separate post.

You’re trying to do 20 data writes to the Blynk server one after another, rather than ensuring that you limit the rate to no more than 1 data write every 0.1 second.

Because you’re flooding the Blynk server with data it’s buffering the incoming data and slowing everything down.

Pete.

Hi Pete,
Thanks for your support, i will try change my code to limit the transmission rate and update.
Apologize i have other similar post that i not aware of…
Once again thanks.

I was referring to post #5 in this topic.
You posted your code there without triple backticks. I asked you to edit that post and add the triple backticks, but you didn’t. As a result had to go in an delete your unformatted code from that post.

Pete.