Why nobody uses bridge?

but still not getting a response from either “slave” devices

What do you mean by this? You don’t have a code on “slaves” that should send something back. Or I’m missing something?

1 Like

HI Dmitriy,

bridge1.digitalWrite(5, LOW);

Should be sending the signal to the other ESP8266-EVB board and activating the relay connected to GPIO5, or am i missing something?

I would expect this to be the same as a button on it’s own “Project” assigned to ~GP5 which works

1 Like

By response i meant an action on the slave device, I would expect the relay / LED to respond, :slight_smile:

What I’m planning to try later is send a virtualwrite to the device and then use the Blynk_Write on the secondary device to pick it up and then trigger the relay instead of the digitalwrite directly to the GPIO.

Does anyone else on the forum have a working example of bridge?

With the testing I have completed this evening I can only determine that the Blynk server is not responding / sending the command to the second device.

As a last resort I will try implement a local server in order to access the logs directly.

To answer the question posed in the Topic, it appears that the Bridge function although possibly useful is not as stable as the rest of the widgets / functions.

It would be better (and possibly more efficient) to implement a token setting in each Widget.

1 Like

@Bobbo_SA

I just open your latest logs and see there “Bridge not initialized”. Which means - either you do not call bridge.setAuthToken() either it is not called for some reason.

1 Like

@Bobbo_SA

okey… I think I know the reason. I missed it first time

if (Blynk.connect()) {

should be :

 while (!Blynk.connect()) {
    // Wait until connected
  }
  bridge1.setAuthToken(authN);

Please try it with above code.

1 Like

Almost,but, :slight_smile: with a slight tweek its finally communicating to the second device - More testing to follow (Seems a bit slow)

...
//Removed the !
...
 while (Blynk.connect()) {
    // Wait until connected
  }
  bridge1.setAuthToken(authN);
...
...

Blagodarya, appreciate the response so late.

Confirmed that i am now able to communicate with 4 additional devices from one primary “Project”.

I will clean up the code (And comment it correctly) on both the Primary devices and secondary devices and post it as an example.

1 Like

Cool! Also have in mind we do not have any “slow” issues so far, so tell us if you have some problems here.

Will do, i expect its just network latency in the links that are not in your control, given that the command has to go from the IOS app -> Blynk server -> Primary Device -> Blynk Server -> Secondary device, so even a 1-2 second delay is quite impressive.

1 Like

As promised, working example of the Bridge function:

Hardware setup:
Primary Device: Arduino Nano V3 + ESP8266 connected via HW Serial
Second Device: Arduino Nano V3 + ESP8266 connected via HW Serial
Third Device: ESP8266-EVB Board
Fourth Device: ESP8266-EVB Board

Code on the “Primary” device that the mobile application connects to:

/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social groups:              http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 *
 **************************************************************
 * Control another device using Bridge widget!
 *
 * App dashboard setup:
 *   3 Buttons connected to V3, V4 and V5
 *   3 LEDs connected to V10, V11, V12
 *   
 **************************************************************/
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266.h>
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleShieldEsp8266.h>

// Set ESP8266 Serial object
#define EspSerial Serial

ESP8266 wifi(EspSerial);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "PrimaryAuthCode";
//Auth Tokens for any additional projects that you would like to control
char auth1[] = "SecondaryAuth1";
char auth2[] = "SecondaryAuth2";
char auth3[] = "SecondaryAuth3";

//Bridge Widget on virtual pin 1 (not currently required in the app)
WidgetBridge bridge1(0);
WidgetBridge bridge2(1);
WidgetBridge bridge3(2);

void setup()
{
// Set ESP8266 baud rate
  EspSerial.begin(115200);  

//Initialize and connect to the Wifi and Blynk service
  Blynk.begin(auth, wifi, "SSID", "PSK");

while (Blynk.connect()) {
// Wait until connected
  }
  bridge1.setAuthToken(auth1);
  bridge2.setAuthToken(auth2);
  bridge3.setAuthToken(auth3);
  }

//The reads the state of a Button in the App assigned to virtual pin 3
BLYNK_WRITE(3) {
  int a = param.asInt();
  if (a == 0) {
//Turn Off pin 5 on the other device
    bridge1.digitalWrite(5, LOW);
    } else {
//Turns on pin 5 on the other device  
    bridge1.digitalWrite(5, HIGH);
    }
//Turns on a LED connected to Vitrual pin 10 in the mobile App
  Blynk.virtualWrite(10, a);
 }

//The reads the state of a Button in the App assigned to virtual pin 4
BLYNK_WRITE(4) {
  int a = param.asInt();
  if (a == 0) {
//Turn Off pin 5 on another device
    bridge2.digitalWrite(5, LOW);
    } else {
//Turn on pin 5 on another device
    bridge2.digitalWrite(5, HIGH);
   }
//Turns on a LED connected to Vitrual pin 11 in the mobile App
  Blynk.virtualWrite(11, a);
 }

//The reads the state of a Button in the App assigned to virtual pin 5
 BLYNK_WRITE(5) {
  int a = param.asInt();
  if (a == 0) {
//Turn off pin 13 on another device
    bridge3.digitalWrite(13, LOW);
    } else {
//Turn on pin 13 on another device
    bridge3.digitalWrite(13, HIGH);
   }
//Turns on a LED connected to Vitrual pin 12 in the mobile App
  Blynk.virtualWrite(12, a);
 }

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

Code on the ESP8266-EVB board - this board has a relay on pin 5:

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

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

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, "SSID", "PSK");
  pinMode(5, OUTPUT);
}

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

I’m kind of new, but I had to reply to this.

Currently I’m working on several projects and one of them is automating a Lego train track. This entails the driving of multiple trains on a single piece of track. I’m using Arduino’s for this but I’m thinking about incorperating the Blynk App for more control.

Since I’m using multiple Arduino’s to control the tracks (for example, one for train detection/running and one to control the signposts) this will be of very good use to me! Thanks so much for sharing!

3 Likes

Great! Can you post a video of it working together? It would be so cool!

Heh +1 for video, very interesting to see some real use case with bridge.

2 Likes

Yip, will do tonight.

Got another “use case” for the bridge function that i tried out last night.

I have a PIR and ESP shield on one Arduino and a second ESP with a standard light bulb connected via the relay - the light bulb could be any output device i.e. siren, buzzer etc - When Arduino #1 senses movement it sends the digitalwrite (Via blynk) to the second device to turn on the light, so no phone app in between.

Basically I am in the process of making up some internet connected Wifi security sensors that will alert me to movement around the house and garden.

3 Likes

D, question, is Bridge supported on the ESP device directly?

On both my Nano’s that use the ESP as a shield it works 100%, but I’m trying to get it to work on an ESP8266-EVB board, but it hangs up at the “While(Blynk.connect())”, even though if i comment that section out then it works via its own dashboard.

1 Like

It should work. But I’m not sure get you right.

it hangs up at the “While(Blynk.connect())”

How this is related with Bridge itself?

maybe it should be

While(!Blynk.connect()) {}

or

While(Blynk.connect() == false) {}
1 Like

This is part of the Setup / initialization code that we got working on the earlier verion:

...
 while (Blynk.connect()) {
    // Wait until connected
  }
  bridge1.setAuthToken(authN);
...

What i am attempting to do is create a situation where the App communicates with multiple devices via a primary Arduino and then each of the other devices can return a status / value / message back to the Primary Arduino and then to the App, something like:

  1. Dashboard Button Press
  2. Primary Arduino Receives the button push
  3. Primary sends signal to standalone ESP#1 via Bridge
  4. Standalone ESP to Perform Activity
  5. Standalone ESP#1 replies to Primary Arduino via bridge
  6. Display status in Dashboard

I was struggling with getting the ESP to communicate back to the primary Arduino

Simply trying to establish a bi-directional communication via the bridge function between the devices and the App (using multiple devices on one dashboard)

1 Like

Hey, did you read my answer?..