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

Bridge Vpin explanations

#1

Good morning!

I managed to make the bridge work, but I don’t understand how the various vpins connected to it work.

Which is the meaning of “WidgetBridge bridge1 (V21)” in the sketch emitter if then in the same sketch I can make the bridge with other Vpins (in this case I can read in the receiving sketch V21, V22 and V23) without initializing all the Vpins but only the V21? (which then, even if the associated widget is not added to the app, everything works properly.)

WidgetBridge bridge1(V21); //why V21??

BLYNK_CONNECTED() {
  bridge1.setAuthToken("receiver token");
}

void ->
bridge1.virtualWrite(V21, t_buffer1);
bridge1.virtualWrite(V22, t_buffer2);
bridge1.virtualWrite(V23, t_buffer3);

And I don’t understand in the receiver how to set the Vpins … that is, with this receiver sketch I read all the correct data on the serial, perfect, but I don’t understand what we are talking about, whether of the receiver or the emitter:

BLYNK_WRITE(V21) { 
  Blynk.virtualWrite(V21, param.asFloat ());
  sanitaria = param.asFloat ();
  Serial.println(sanitaria);
}

BLYNK_WRITE(V22) {
  Blynk.virtualWrite(V22, param.asFloat ());
  boiler1 = param.asFloat ();
  Serial.println(boiler1);
}

BLYNK_WRITE(V23) {
  Blynk.virtualWrite(V23, param.asFloat ());
  boiler2 = param.asFloat ();
  Serial.println(boiler2);
}

And last thing: if I wanted to have two or more emitter and one only receiver, how should I behave? On the variuos emitter I have to change the bridge name (like this code) or I can always use the same name and just change the various Vpins?

BLYNK_CONNECTED() { // in first emitter sketch
bridge1.setAuthToken("receiver token xyz");
}

BLYNK_CONNECTED() { // in second emitter sketch
bridge2.setAuthToken("receiver token xyz");
}

BLYNK_CONNECTED() { // in xxx emitter sketch
bridge3.setAuthToken("receiver token xyz");
}

can someone better explain this aspect to me? thank you

0 Likes

#2

You are basically using an available vPin as a placeholder for the Bridge. Each Bridge define needs its own vPin, and that vPin is not used for anything else.

So you simply define a source Bridge name to a vPin and call that Bridge by said name AKA bridge1 to control the desired vPin of the targets device/code.

Thus…

Uses the source device/code virtual pin V21 to “assign/store/whatever” the bridge named bridge1

while…

This command for bridge1 in the source device/code sends the data in t_buffer1 to the target device/code virtual pin, also named V21 - But, the correlation between vPin numbers is irrelevant and they can be totally different from each other as they are referring to seperate devices.

1 Like

#3

Thanks @Gunner!!

And for the last two quesions? :slight_smile:

0 Likes

#4

FYI, I figured most of this bridge stuff out via trial and error… often quicker the waiting for answers :stuck_out_tongue_winking_eye:

An assigned bridge is referencing a single Auth, AKA a specific device, so sending to different vPins on that same device is all you need to do…

If you want to send data and/or control multiple receiving devices (eg. device A, B & C) then you have to define multiple bridges, one for each.

WidgetBridge bridgeA(vPin1);  // Use free unused vPins from sending device
WidgetBridge bridgeB(vPin2);  // Each define needs its own vPin
WidgetBridge bridgeC(vPin3);  // These vPins have no association with the receiving devices.
BLYNK_CONNECTED() {
  bridgeA.setAuthToken("aaaaaaaaaa"); // Token of the receiving hardware A
  bridgeB.setAuthToken("bbbbbbbbbb"); // Token of the receiving hardware B
  bridgeC.setAuthToken("cccccccccc"); // Token of the receiving hardware C
}
bridgeA.virtualWrite(V0, ValueForV0);  // Sending value to receiving device A vPin
bridgeB.virtualWrite(V1, ValueForV1);  // Sending value to receiving device B vPin
bridgeC.virtualWrite(V2, ValueForV2);  // Sending value to receiving device C vPin

BTW, you can assign any variable name to a bridge if that makes it easier to manage in your code

WidgetBridge BoilerDevice(vPin1); 
WidgetBridge PumpDevice(vPin2);
WidgetBridge LightingDevice(vPin3);
1 Like

#5

No no, everything works, but I also like to understand why it works :slightly_smiling_face:

Perfect, so this (bridgeA bridgeB bridgeC) is ok with multiple receivers devices. In the case of a single receiver device, so I can always use in every emitting device:

EMITTER 1:

WidgetBridge receiverDevice(V1); 

BLYNK_CONNECTED() {
  receiverDevice.setAuthToken("receiver token");
}

void ->
receiverDevice.virtualWrite(V21, t_buffer1);
receiverDevice.virtualWrite(V22, t_buffer2);
receiverDevice.virtualWrite(V23, t_buffer3);

and, in other emitting device, I can use the same syntax, being careful to use different Vpin for the receiver. Correct?

EMITTER 2 to same receiver:

WidgetBridge receiverDevice(V2); //or V1 too indifferently?

BLYNK_CONNECTED() {
  receiverDevice.setAuthToken("receiver token");
}

void ->
receiverDevice.virtualWrite(V31, t_buffer1); //no V21 because used by emitter1
receiverDevice.virtualWrite(V32, t_buffer2); //no V22 because used by emitter1
receiverDevice.virtualWrite(V33, t_buffer3); //no V23 because used by emitter1

Ok, maybe until now I understood :slight_smile:

But in the receiver …

BLYNK_WRITE(V21) { //this mean: WHEN V21 (OF RECEIVER, this DEVICE) CHANGE (like a WIDGET BUTTON PRESS) with the command in emitter1 "receiverDevice.virtualWrite(V21, t_buffer1)", than:
  Blynk.virtualWrite(V21, param.asFloat ()); //READ the param.asFloat of the V21
  abcd = param.asFloat (); //and store the data in "abcd" variable
}

//and then

BLYNK_WRITE(V31) { //this mean: WHEN V31 (OF RECEIVER, this DEVICE) CHANGE with the command in emitter2 "receiverDevice.virtualWrite(V31, t_buffer1)", than:
  Blynk.virtualWrite(V31, param.asFloat ()); //READ the param.asFloat of the V31
  efgh = param.asFloat (); //and store the data in "efgh" variable
}

It’s correct?

My confusion comes from the fact that I go to READ with a WRITE command, which I can’t conceive yet :slight_smile::

Blynk.virtualWrite(V31, param.asFloat()); 
efgh = param.asFloat(); 

Thanks very much @Gunner :):smiley:

0 Likes

#6

Like this

BLYNK_WRITE(V31)
{
  efgh = param.asFloat();
}

BLYNK_READ(V31)
{
  Blynk.virtualWrite(V31, efgh);                                
}
1 Like