What is behind BLYNK_WRITE()?

Hi, I am wondering if there is any way to determine what kind of Widget is behind BLYNK_WRITE() function or what is the payload type(bool, int, array etc.) in order to automate the action when manually change the widget. (something like “param.asWidgetType()”)

Not sure of your question…

As per the documentation… BLYNK_WRITE(vPIN) is a code function that gets called when the associated vPIn has new data… this update is sent from the Server, which in turn gets it from any associated Widget in the App, another device via Bridge, or perhaps via an API.

As for the mechanics of the function, spend some time looking through the library files if you wish a closer look… https://github.com/blynkkk/blynk-library

1 Like

… by saying “behind” meant not “the mechanics of the function” but which is the associated Widget in the App.
How could this be retrieved from the hardware side? Is it a button? a slider? a joystick? what?
so… once widget (or payload type) is known then different actions can automatically be triggered if the widget in app change!

Perhaps reading the documentation (Docs and Help Center) and looking at the examples (in the Sketch Builder) might help? :stuck_out_tongue_winking_eye: All these links are at the upper right of this page… scroll up if you can’t see them.

The “associated” widget is whatever widget you assign or associate to the same vPin, in both the App and the BLYNK_WRITE(vPIN) function.

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/what-is-virtual-pins

A virtual pin is just that, a pin, but virtual. As with hardware pins it doesn’t matter what kind of “sensor” is behind it (you could also read “widget” or “button”).

It’s a matter of transferring data to/from the hardware, e.g. Input and Output :slight_smile:

yes… all the above is understood and thank you for the responses but currently trying to build a bridge to transparently forward the payload from a virtual pin (any type) to RF Network (NRF24) so will be able to remotely(RF) … control relay (s) or… set delay time for a timer or… to control a servo(x.y) or… whatever!
…for that purpose need somehow to retrieve the payload type (int, float, x.y array…) pass it in the message body then send it to remote node… finally decode in destination node the payload according to the payload type that previously retrieved in blynk node. for example…

 /* i know this is not a working code!!! 
  *  just trying to demonstrate the thought
  * 
  */

// BLYNK NODE with internet access & RF MODULE attached
for (int i; i<=vPINnumbers; i++){
 BLYNK_WRITE(i) // yes it does't work that way!!
{
  byte msgtype = param.whatIsTheWidget(); // retrieve somehow the widget type so i will a picture of what i have to deal with.
  send.RFmsg(destination,msgtype,param.buffer(),param.length()); // send msg according RF library 
}
}

 // DESTINATION NODE with RF MODULE attached and ... whatever else
 void recieve(){ // Retrieve message according RF library
  byte RFmsgtype = message.type();
  byte RFmsgLength = message.length();
  long Payloal = message.PAYLOAD
  .
  .
  .
 }

Hope all the above make sense!(as a concept) if not, how could this be achieved?

You mean Blynk’s data protocol? Just a forum search away :wink:

It does make sense :slight_smile:

http://docs.blynk.cc/#blynk-main-operations-virtual-pins

Have you seen that? It explains both ways. Writing to a vPin (with any type of data) and reading vPins from the App.

I think it explains quite clear how you can use virtual pins. The concept can be a bit difficult to grasp, I’ll admit I was having trouble with it too in the beginning.

Now it makes perfect sense though. I hardly use any digital or analog pins anymore. If you attach everything to virtual pins the whole Blynk platform becomes so much more powerful.

I think I get it now… the OP wants to take some setting from the App and use the same vPin backend to send/receive data to/from non Blynk controlled RF devices…

@andromedas if so, then well you could try to figure it out out yourself I guess with the protocol…

However, Virtual pins are designed for within the Blynk infrastructure. But nothing says you can’t take, for example, joystick coordinates sent to a MCU via virtual pins then have the MCU convert same coordinates out to an RF receiver for physical control… but that last part is non-Blynk specific coding and up to you to manage.

Xmm! Playing with Blynk Protocol is too much for me!
i will try to retype my original post!
… is any way to determine from hardware side what kind of widget is assigned to a vPin in order to drive to different actions?
something like…

BLYNK_WRITE(Vpin)
{
if (assigned.button) button(param1,param2);
else if (assigned.slider) slider(param3,param4);
else if (assigned.joystick) joystick(param5,param6);
else if ....
else if ....
.
.

}

I think it’s better now! (also think the answer will be the same!)

Yes, parse the json project file.

Could you please give me a link or an example to start with?

… something like this?

Check Blynk’s API but basically this:

http://blynk-cloud.com/[token]/project

Oh, that hurts! but i will give a try! :face_with_raised_eyebrow: Thanks @Costas

1 Like

I know it’s a late response but I am looking for the same thing. I am using Node-Red and detect single, double and long taps on a button. I want the BLYNK_WRITE message to be passed through a generic handler that detects the button events but simply passes on messages from non-buttons unchanged.
The only way I can do it safely is to keep a list of button virtual pins which makes life difficult, so a (maybe optional) widget type in the message would be very useful.
BTW, I am running a local server - network delays might make the detection unreliable otherwise.
Another solution might be for the app to do the detection and pass a suitable payload.