Why nobody uses bridge?

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?..

Ill bought another ethernet modul, and i ll try it. :wink:

1 Like

Yip, testing it now.

This worked: :smile:

...
    while(Blynk.connect() == false) {}
    
    //while(!Blynk.connect()) {}   **This way round did not work, the effect should be exactly the same though?

     bridgeMain.setAuthToken(authMain);
      
    }
...
1 Like

Still doing some tweaks, making changes and trying to document the design a bit better but this is my current Dashboard, once i have all the code cleaned and and commented sufficiently to make sense I will upload it.

The Dashboard has 2 LEDs per button, the first LED is to indicate that the signal has been sent and will most likely be removed once its deployed, the second LED though is a signal from the device to indicate its current status.

Most of the devices will display the status on the app as well as to the device called “Bedroom monitor” that has an OLED screen, small buzzer and 2 relays for controlling the bedside lights.

Bridge is a key component to this design as it allows for bi-directional communication as well as being able to communicate to multiple devices.

The intention with the PIR motion sensors is hopefully to utilize the notification widget once it has been deployed in IOS, currently they just trigger the buzzer on the bedroom monitor and flash the LED widget in the application.

5 Likes

Great job! Looking forward to seeing the final result!

Once your project is ready, it would be great to put it into the Projects made with Blynk category. So that anyone can easily find it without digging the whole forum

Thanks for sharing!

I will do, apologies for “hijacking” this thread, :smiley:

i already asked you before for how to connect Arduino Nano + ESP-01
and you give me a link http://contractorwolf.com/esp8266-wifi-arduino-micro/
and it’s for Micro not Nano.
i still stuck on connecting the Nano with ESP-01 on HW serial
if you can provide me with it and working blink example i will be very thankfull

I used his example and by comparing the 2 datasheets matched the pins up, the only ones that were different are the power and ground pins.

3 Likes