More than two ESP's in bridge

It’s really not hard to get this working. I use a main Arduino attached to Ethernet to control several ESP’s in bridge mode. I use the same auth for all ESP’s and use Virtual pins from the main Arduino. That’s basically it.

I have it running one ESP with two relays switching an outlet and some lights, a Nano with ESP as shield to PWM my dinner table lamp, another ESP in standalone to automatically light the hallway LED strip and last but not least, another ESP with two more relays controlling outlets for anything I like to plug in when it springs to mind (think Coffeemachine, lights for a terrarium, whatever).

Super bravo !!! (but give us drawings, photos and code to dublicated what we like !) …

I think we all know how to hook up the ESP by now. There are plenty of topics on that. Usually I’m not very willing to act as a code factory, but I’ll give you an example of how I use the it. Situation:

  • Arduino with Ethernet connection to network (could be another ESP though)
  • One ESP who triggers a simple pin, LED strip perhaps?
  • Another ESP to trigger two relays

Arduino code

#include <UIPEthernet.h>                  // Ethernet lib
#include <BlynkSimpleUIPEthernet.h>       // Blynk Ethernet add-ons

WidgetBridge lights(31);

// (V)24, (V)25     = Boxed ESP-01 relays living room lights
// (V)23            = Hallway LED strip

BLYNK_WRITE(V23)
{
  int valueV23 = param.asInt();
  lights.virtualWrite(V20, valueV23);
  }

BLYNK_WRITE(V24)
{
  int valueV24 = param.asInt();
  lights.virtualWrite(V21, valueV24);
}

BLYNK_WRITE(V25)
{
  int valueV25 = param.asInt();
  lights.virtualWrite(V22, valueV25);
}

BLYNK_CONNECTED()
{
  lights.setAuthToken("remoteESPtoken"); // Used to have problems with remote tokens, this solves that
  Blynk.syncAll(); // Sync stuff, I do this by default
}

void setup()
{
  Blynk.begin(auth)
}

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

ESP with LED attached:

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

char auth[] = "remoteESPtoken";

BLYNK_WRITE(V20)
{
  int valueV20 = param.asInt();
  if(valueV20 == 1)
  {
    digitalWrite(0, HIGH); 
  }
  else
  {
    digitalWrite(0, LOW);
  }
}

void setup()
{
  Blynk.begin(auth);
}

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

Other ESP with two relays:

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

char auth[] = "remoteESPtoken";

BLYNK_WRITE(V21)
{
  int valueV21 = param.asInt();
  if(valueV21 == 1)
  {
    digitalWrite(0, HIGH); 
  }
  else
  {
    digitalWrite(0, LOW);
  }
}

BLYNK_WRITE(V22)
{
  int valueV22 = param.asInt();
  if(valueV22 == 1)
  {
    digitalWrite(2, HIGH); 
  }
  else
  {
    digitalWrite(2, LOW);
  }
}

void setup()
{
  Blynk.begin(auth);
}

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

I hope this clears things up a bit. The trick is to recycle the auth code for remote devices. That way you can use the virtual pins to control them. The other way around it will work too. You could send data from the ESP back to the Arduino, for example for a wireless sensor in your shed, garden or greenhouse.

2 Likes

Hi everyone. Got some kind of same problem.
Got alot of esp01 and esp12 for pir sensors and blynkserver. I need all of them to pull and push only one same relay on last esp.All esps got different token. But bridge function works only for two of them! Is it somekind of payment feature? Or it my sketch code bug?

Sample code just to controll 3 relay from 4th dashboard(works only bridge1 and bridge2)

char auth[] = “mastertoken”;
char auth1[] = “slave1token”;
char auth2[] = “slave2token”;
char auth3[] = “slave3token”;
WidgetBridge bridge1(V20);
WidgetBridge bridge2(V21);
WidgetBridge bridge3(V22);
void setup()
Blynk.begin(auth, “SSID”, “PASS”, IPAddress(SOME,INTERNAL,IP,ADRESS));
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
pinMode(0, OUTPUT);
digitalWrite(0, HIGH);
pinMode(3, OUTPUT);
digitalWrite(3, HIGH);
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
pinMode(5, OUTPUT);
digitalWrite(5, HIGH);
pinMode(12, OUTPUT);
digitalWrite(12, HIGH);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
pinMode(14, OUTPUT);
digitalWrite(14, HIGH);
pinMode(15, OUTPUT);
digitalWrite(15, HIGH);
pinMode(16, OUTPUT);
digitalWrite(16, HIGH);
while (Blynk.connect() == false) {
// Wait until connected
}
bridge1.setAuthToken(auth1);
bridge2.setAuthToken(auth2);
bridge3.setAuthToken(auth3);
}

BLYNK_WRITE(V30) {
int a = param.asInt();
if (a == 0) {

bridge1.digitalWrite(5, LOW);
} else {

bridge1.digitalWrite(5, HIGH);
}
}

BLYNK_WRITE(V31) {
int a = param.asInt();
if (a == 0) {

bridge2.virtualWrite(1, LOW);
} else {

bridge2.virtualWrite(1, HIGH);
}
}

BLYNK_WRITE(V32) {
int a = param.asInt();
if (a == 0) {

bridge3.virtualWrite(1, LOW);
} else {

bridge3.virtualWrite(1, HIGH);
}
}
void loop()
{
Blynk.run();
}

if I del bridge3 everythere and set any slave token ether slave2 or slave3, ill be able to push or pull relay of slave2/3 esp via master dasboard!

I just use one slave token for all slave devices and handle everything with vPins from the master device. E.g. vpin 1 is for slave device 1, vpin 2 for slave device 2, 3 and 4 for slave device 4 and so on.

Pal…
Here is some problem with that!
if i got 7 esp01 so i got 7 slave with same token.
All of those esp01 got only gpio2 and gpio0.
If I bound gpio2 from esp01 1…7 to virtual pin 1…7 in its sketches will it work in main esps dashboard?
bridge1.virtualWrite(1…7,HIGH) ?

It’s like in the code I wrote above your post.

Catch the values on the ESP side with different Vpins too.

You can show this sketch?
Thanks.