Using BLYNK_WRITE() with Bridge

HEY GUYS
I have a prblem with the BLYNK_WRITE( ) .
I’m using two esp nodemcu blynk based . one of them is creating the bridge between them . the other one is just checking the virtual pins and recieve orderfrom the first one .

when i used the BLYNK_WRITE( ) in the 2nd one (slave) it works . but when I use it in the (master) it doesn’t work
is there any issues in using the blynk bridge with the blynk write ?





#define BLYNK_PRINT Serial

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

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXX";
char pass[] = "XXXX";
int pinData;
#define DHTPIN 4 // What digital pin we're connected to

#define DHTTYPE DHT11   // DHT 11
 // #define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
WidgetBridge bridge1(V1);
  BLYNK_WRITE(V8) 
  {

 pinData = param.asInt(); 
 
  }


BLYNK_CONNECTED() {
  // Place the AuthToken of the second hardware here
  bridge1.setAuthToken("1e15f8dXXXXXXXXXXXXXXXX"); 
}

void sendSensor(){
  // get readings from the DHT22 sensor
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit


  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  
 Serial.print("recieved ");
     Serial.print(pinData);
 

 
}

void setup(){
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  dht.begin();

  timer.setInterval(500L, sendSensor);
}

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

Possibly because you are not even using any bridge command to send data to your receiving device? :stuck_out_tongue_winking_eye:

E.g.

bridge1.virtualWrte(vpin, value) // send value to vPin on receiving device
1 Like

you are right :smile:
but i want to make sure that i understand well , so every time i send data I must creat a bridge from the sender device ?
is there any other easier way to check a virtual pin on the blynk server ?

Wel, you create the bridge once in the sending sketch, then use it as many times and with whatever (receiver) vPins you need… as long as there is a corresponding Blynk function on the receiver’s device it will work just as if you have activated those functions from it’s project.

Not sure I follow your question in the context of this topic.

yes that is actually what i’ve done the above code is the sender ESP which worked very well when i tried to send data to the reciever but i deleted the lines .
when i tried to send data from the receiver to the sender … it didn’t work thats why there is no bridge1.virtualWrte(vpin, value) in the above code … but here is the code of the receiver or the SLAVE esp , when i tried to send data back to the MASTER , nothing recieved .

int pinData;
char c=' ' ;
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>

#include <BlynkSimpleEsp8266.h>
#include<SimpleTimer.h>
SimpleTimer timer;
SoftwareSerial esp(14,12);

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

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

// This code will update the virtual port 5
BLYNK_WRITE(V5) {
 pinData = param.asInt(); 
 
}
void led(){
Blynk.virtualWrite(V8,'b');
}



void setup(){
  Serial.begin(115200);
  esp.begin(9600);  
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, led);
}

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

Check out that link I posted above…

Blynk Bridge is a one-way link… if you want to send data both ways you need to set up another independent Bridge on the other device pointing back to this one.

1 Like

okay i got your point as its one way link , but i don’t want to use bridge1.virtualright , I want to use blynk.virtualwrite then read from it so by this way i am checking from the server not from the links of the bridge it self

Everything goes to and is received from the server :wink: It doesn’t matter whether you use a button, slider, etc. to send some data (from the receivers own project) or the Bridge sends the data (from another devices code)… the receiver gets the same info from the Server and reacts the same way.

Now if you want to update a BLYNK_WRITE() function with last stored value from the server, use Blynk.syncVirtual(vPin) But that is not used in the same context as Bridge as this command is ran and processes on the same device… nothing to do with sharing data between devices.

http://docs.blynk.cc/#blynk-firmware-virtual-pins-control-blynksyncvirtualvpin

thank you my friend :sunglasses: , I’ve tried to trigger a virtual pin from device 1 then check wether it is triggered or not from device 2 but it seems that something like this is little bit hard to me on blink

The only way I can think of for getting feedback of a bridge action is by sending the feedback back… by another bridge :slight_smile:

However, your device will have absolutely no idea if the action was triggered via the App or the Bridge… so feedback like that might not be what you are wanting.