Pleace help me with blynk.virtualWrite

I was trying to use one token for 2 esps. One of them are equiped with motion sensor and another with relay board.
At the begining i wrote sketch wich send to vpin V25 fact of changing state of pin4, but my relay module on second esp did not turn on/off. so i desided to write sketch for one esp using virutalpin(just to check whatever virtualpin 25 turns digital pin 5 on or off).
But it was fail! whose sketch below only turn on and off widget state in android app, but not the relay! Please someone help me! What am I doing wrong?
(solution with digitalWrite on pin 5 did not suite for me, cause i need to send V25 remotly to same token and other esp)

Here is some sketch:

char auth[] = “xxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
boolean state0;

void setup()
{
Serial.begin(115200);
Blynk.begin(auth, “”, “”, IPAddress(,,,));

pinMode(4, OUTPUT);
digitalWrite(4, LOW);
pinMode(5, OUTPUT);
digitalWrite(5, LOW);
pinMode(4, INPUT);
}

bool isFirstConnect = true;
BLYNK_CONNECTED() {
if (isFirstConnect) {
Blynk.syncAll();
}
}

BLYNK_WRITE(V25)
{
if (param.asInt() == 1)
{
digitalWrite(5, LOW);
}
else
{
digitalWrite(5,HIGH);
}
}

void loop()
{
if(state0 != digitalRead(4))
{
state0 = digitalRead(4);
Blynk.virtualWrite(V25,state0); // I think the PROBLEM IS HERE))))
}

Blynk.run();
}

If i power 2 my ESPS with same token, remove BLYNK_WRITE(V25) directive and write it on second ESP, the relay module will turn off and on with android app on second esp. So i think the problem is with “virtualWrite”)))

Yes, what you are doing here is totally not recommended and it’ll mess up your program :slight_smile:

Take a look at the PushData example to see how you can send data using a little library called SimpleTimer. If you do a virtualwrite in the loop it sends too much data because the loop get executed several 100, possibly 1000’s of times per second.

Pal! Take a look at my code and carefully read all i wrote! It do virtualwrite only at changestate fact, not every nanosecond! If it ll be so as you described ill get thousends of disconnects, but that does not happend! If i put digitalwrite there it works perfectly!

Yeah but it is still not recommended, so please try with simpletimer and out of the loop. The engineer who makes the library even recommends to not put it there, so there must be a good reason :slight_smile:

As a fact it was my fault - i find some logical mistake - now it works. But it canot work without bridge