Multiple ESP8266

Hi! Just started using blynk and it’s working perfectly so far! I can switch an LED on my ESP8266 from my phone.

So, next step, five esp’s controlled with one project. I am not sure if I understood everything about bridging. At this moment I only have 1 esp so I can’t test it yet, but I would like to share my code. If I understand correctly, I will make one “master” blynk project and 4 “slaves”. The master project controls the pin on the esp it’s connected to and 4 virtual pins. So 5 buttons in total. The projects for the “slaves” are empty, I only need their autorization code. I upload the esp standalone example to the slaves and the following to the master. Is any of this correct?


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

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
WidgetBridge bridge1(V1); 
WidgetBridge bridge2(V3); 
WidgetBridge bridge3(V5); 
WidgetBridge bridge4(V7); 
void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "ssid", "pass");
}

void loop()
{
Blynk.run();


}

BLYNK_CONNECTED() {
  bridge1.setAuthToken("OtherAuthToken");
  bridge2.setAuthToken("OtherAuthToken");
  bridge3.setAuthToken("OtherAuthToken");
  bridge4.setAuthToken("OtherAuthToken");
}

BLYNK_WRITE(V2) 
{
    if (param.asInt()) {
        //HIGH
        bridge1.digitalWrite(2, HIGH);
    } else {
       //LOW
       bridge1.digitalWrite(2, LOW);
    }
}


BLYNK_WRITE(V4) 
{
    if (param.asInt()) {
        //HIGH
        bridge2.digitalWrite(2, HIGH);
    } else {
       //LOW
       bridge2.digitalWrite(2, LOW);
    }
}

BLYNK_WRITE(V6) 
{
    if (param.asInt()) {
        //HIGH
        bridge3.digitalWrite(2, HIGH);
    } else {
       //LOW
       bridge3.digitalWrite(2, LOW);
    }
}


BLYNK_WRITE(V8) 
{
    if (param.asInt()) {
        //HIGH
        bridge4.digitalWrite(2, HIGH);
    } else {
       //LOW
       bridge4.digitalWrite(2, LOW);
    }
}

Hello. Seems ok. You can also consider using same token for your ESPs in that case command will be send to all ESPs.
So every specific ESP will have separate handler for command :

//esp1
BLYNK_WRITE(V2) 
{
   //do something
}

.

//esp2
BLYNK_WRITE(V2) 
 {
        //do something
}

This approach is easier than bridge.

1 Like

Aaah right!

So every arduino will respond to a different virtual pin. That seems a lot easier, thanks!

Okay, not sure if my problem is hardware or software atm but this is my setup: in blynk I have 4 buttons switching virtual pins (V0, V1, V2 and V3). The esp’s are on the same token and network, only difference is the virtual pin they respond too.

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


char auth[] = "token";

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "ssid ", "pass");
}

void loop()
{
Blynk.run();


}



BLYNK_WRITE(V0) 
{
    if (param.asInt()) {
        
        digitalWrite(2, HIGH);
    } else {
      
       digitalWrite(2, LOW);
    }
}

In case you don’t use digital pin directly via blynk you have to manually set PinMode for it. Or you can set button to work with digital pin directly.