Bridge=>> digitalWrite Virtual pins issue

Using two ESP8266’s standalone one using bridge mode and the otherone not, which works.

Next to controlling hardware pins at the other side of the bridge I wanted to send values to the other side using the virtual pin.

The “bridge” esp is using this code (attached to a timer):
void knipper() {
if (aanuit == true) {
bridge1.digitalWrite(2, HIGH);led15.on();aanuit=false;bridge1.digitalWrite(V21,13);}
else{bridge1.digitalWrite(2, LOW);led15.off();aanuit=true;bridge1.digitalWrite(V21,330);}
}

At the other end of the bridge I have a widget in “push” mode connected to pin V21. Alas no effect visible.
The pin connected to pin “2” is working properly (flashing at 1 sec intervals)

Any ideas?

1 Like

shouldn’t that be bridge1.virtualWrite(V21,330) ?

Yes, I agree it should be virtualWrite . But it did not solve the issue,

1 Like

Ok… You need for example

WidgetBridge bridge1(V30);

In setup, after main connection

 while (Blynk.connect() == false) {
 // Wait until connected
       }
     bridge1.setAuthToken("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
       }

Then use something like
BLYNK_WRITE(V31)
{
slidV20val = param.asInt();
Serial.print("slider val = ");
Serial.println(slidV20val);
bridge1.virtualWrite(V20,slidV20val);
}
This works for me. The widget uses V30, My app has slider using V31, and this value gets sent to V20 on a second esp.

The while loop with Blynk.connect() is the only way I could get it going. It appears that other ‘connected’ sense mechanisms report a connection too early for the bridge auth token to be accepted.

1 Like

Thanks again for the response, I learn from your answer that the input for the bridge instantiation is also a virtual thing.

To be sure to transfer the key I used similar:
while (!Blynk.connect()) { // check connection before setting the bridge
// Wait until connected
}
bridge1.setAuthToken(“bac1d1dbb28d422dbc420febc8e7da53”); // (yes thats my key)

I’m going to try your example to-morrow but I don’t expect it to be a solution as I transmit values e.g. bridge1.virtualWrite(V21,330) . But we will see.

1 Like

Sending values should not be an issue at all. If you find it is, you can always assign values to variables and send those instead.
You might also find you need to change the !Blynk.connect. I remember reading somewhere that it didn’t work for someone, whereas () == false did for some inexplicable reason.

1 Like

Roffey,

Made a brand new sketch starting from an example but so far its not possible to exchange values with virtualWrite. I also included the example you made.

DigitalWrite is working oke. Maybe I have to change the the receiving end of the bridge and make a method that takes the “virtualPin” and writes it to a local “virtualPin”. My effort to find (Google) an example with the exchange of values across the bridge did not show anything.
Thanks for your help.

1 Like

Yes, there is nothing as frustrating as knowing what you want to do, being so close to it working, yet something stupid prevents it. Happens to me all the time! Valuable lessons are learned though, even if you have kicked ten tons out of of something you wished you hadn’t!

My particular blockage was the successful initiation of the bridge authentication, after the main logging on.
My first method appeared to run it too early. ie although feed back indicated that it was connected, some process needed to finish before the actual bridge process started.

Anyway, my esp to which I want to bridge data to, has a slider (V20) which controls spi to a digital pot …

BLYNK_WRITE(V20){
String pinData = param.asStr();  // data comingin
// 0 -1023 data string
slidV20val = param.asInt()/4;
const char* slid_dat =  pinData.c_str();   
Serial.println (pinData);
Serial.print ("slid_dat published data =");
Serial.println(slid_dat);
client.publish("outTopic", slid_dat); // mqtt going out
 
 SPI.beginTransaction(SPISettings(1000000,MSBFIRST,SPI_MODE0));
  byte spidata = slidV20val;
  Serial.print(spidata);
  byte spiback;
  int numdata=0;
  digitalWrite(16,LOW); //chip select low
  SPI.transfer(0);
  SPI.transfer(spidata);
  digitalWrite(16,HIGH);
  digitalWrite(16,LOW);   
  SPI.transfer(1);
  SPI.transfer(spidata); 
  SPI.endTransaction();
  digitalWrite(16,HIGH); //chip cs high and transfer data 
}

This works with dashboard 1, for instance, so I know it works.
Now I want to use a dashboard 2 ,which controls other stuff, to include a slider which sends its value to dashboard 1 and mimics dashboard 1’s V20 slider.

So, the second esp uses a virtual pin as the bridge communication WidgetBridge bridge1(V30) and the auth token of the first esp board to initiate the connection process.

I set up a slider on V31, and send a V20 value to the first board, as if it were coming from dashboard 1.
Now, dashboard1 or dashboard2 can control esp 1’s V20 slider.

BLYNK_WRITE(V31)
{
  slidV20val = param.asInt();
  Serial.print("slider val = ");
  Serial.println(slidV20val);
  bridge1.virtualWrite(V20,slidV20val);
}

V20 on the first esp now receives a value as if from dashboard1. (one thing I do not know for sure is if V20 on this second (bridge send) esp can still be used).
Looking back, you want to send one of two values, either a 13 or 330. This implies you need to set up a widget that can actually generate and use a value range of this nature. A button widget produces a 0 or 1, so it would not respond?
There are probably other ways but I would either use a button and bridge send a 0 or 1 to it for a dual state, or slider (small to save screen space) if I wanted a range of values to be received. What you control with these values within the BLYNK_WRITE(V’n’) of the receiving esp depends on the application.

Sometimes I need to review things from scratch as it helps my understanding process, so just maybe this might help you.

At last there is WHITE SMOKE. It is necessary to have some code at the receiving end of the bridge to catch the incoming messages. (like in Roffey’s example)
**

The new code in the receiving side is:

**
BLYNK_WRITE(V21)
{
int slidV21val = param.asInt();
Blynk.virtualWrite(24,slidV21val);
}

BLYNK_WRITE(V22)
{
int slidV22val = param.asInt();
Blynk.virtualWrite(23,slidV22val);
}

My code for the transmitting side is:

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = “054d0c9abdad4ea79999464132ec3b7a”;
WidgetBridge bridge1(V30); //Bridge widget on virtual pin v30
SimpleTimer timer;
bool aanuit = false;
bool aanuit1 = false;
int val = 0;
int val1 =1024 ;
WidgetLED led13(V13);
WidgetLED led14(V14);
WidgetLED led15(V15);

void setup()
{
Serial.begin(9600);
delay(5000);
Serial.println(“Start”);
Blynk.begin(auth, “JOKER”, “???”);
Serial.println(“Start”);

while (Blynk.connect() == false) {
// Wait until connected
}
delay(1000);
bridge1.setAuthToken(“967741c612dc4706mxmxmb4a5517023470241”);
timer.setInterval(5000L, knipper);
timer.setInterval(2000L, knipper1);
}
void loop()
{
Blynk.run();
timer.run();
yield();
}
void knipper() {
val++;if (val==1023){val=0;}
if (aanuit == true) {
led15.on();bridge1.digitalWrite(2,HIGH);bridge1.virtualWrite(V22,val);aanuit=false;}
else{led15.off();bridge1.digitalWrite(2,LOW);bridge1.virtualWrite(V22,val);aanuit=true;}
}
void knipper1() {
val1–; if (val1==0) {val1=1023;}
if (aanuit1 == true) {
led14.on();bridge1.digitalWrite(5,HIGH);bridge1.virtualWrite(V21,val1);aanuit1=false;}
else{led14.off();bridge1.digitalWrite(5,LOW);bridge1.virtualWrite(V21,val1);aanuit1=true;}
}

My code for the receiving side is:

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = “967741c612dc4706b4asss5517023470241”;

SimpleTimer timer;
bool aanuit = false;
bool aanuit1 = false;
WidgetLED led13(V13);
WidgetLED led14(V14);
WidgetLED led15(V15);

void setup()
{
Serial.begin(9600);
delay(5000);
Blynk.begin(auth, “JOKER”, “???”);
while (Blynk.connect() == false) {
// Wait until connected
}
//bridge1.setAuthToken(“967741c612dc4ddd706b4a5517023470241”);
timer.setInterval(500L, knipper);
timer.setInterval(1000L, knipper1);
}

void loop()
{
Blynk.run();
timer.run();
yield();
}
BLYNK_WRITE(V20)

BLYNK_WRITE(V21)
{
int slidV21val = param.asInt();
Serial.print("slider val v21 = ");
Serial.println(slidV21val);
Blynk.virtualWrite(24,slidV21val);
}

BLYNK_WRITE(V22)
{
int slidV22val = param.asInt();
Serial.print("slider val v22 = ");
Serial.println(slidV22val);
Blynk.virtualWrite(23,slidV22val);
}

void knipper() {
if (aanuit == true) {
led15.on();aanuit=false;}
else{led15.off();aanuit=true;}
}

void knipper1() {
if (aanuit1 == true) {
led14.on();aanuit1=false;}
else{led14.off();aanuit1=true;}
}

1 Like