BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Trying to use bridge


#1

I have an Arduino Yun driving with a sketch for thermostat, controlling radiators and hot water production. The Blynk app is working fine, giving me a history graph of temperatures, sliders to set target temperatures, and leds, and a button to request hot water outside normal hours.

The main Arduino has a DHT22 sensor, as well as the output relays, but I want to use other EPS8266 devices (adafruit feather) to provide DHT22 data from other rooms and from outside.

I have used the Bridge example on the ESP8266 as follows:

/**************************************************************

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

#include “DHT.h”
#define DHTPIN 12 // what digital pin we’re connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE, 30);
float humidity, temp_f; // Values read from sensor

SimpleTimer timer;

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

// Bridge widget on virtual V10
WidgetBridge bridge1(V10);

void HomeWork()
{
temp_f = dht.readTemperature(false)- 1.8;// Read temperature as Celsius
humidity = dht.readHumidity();

bridge1.virtualWrite(V3,temp_f);
bridge1.virtualWrite(V13,humidity);
Blynk.virtualWrite(V3,temp_f);
Blynk.virtualWrite(V13,humidity);
Serial.println(temp_f);
Serial.println(humidity);
}

void setup()
{
Serial.begin(115200);
Blynk.begin(auth, “SSID”, “PWD”);
dht.begin();
timer.setInterval(10000, HomeWork);

while (Blynk.connect() == false) {
// Wait until connected
}
bridge1.setAuthToken("…");

}

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

The above seems to be running fine, and I can see updates on a separate project app for the EPS8266. But I cannot see any updates on the master app.

Questions:

  1. Should I have a BLYNK_WRITE(V3) handler in the receiving sketch ? If yes, how to I take the value ? the param.asFloat() does not work.
  2. What is the virtual pin number - V10 - in the WidgetBridge bridge1(V10) for? Is it a way to identify the bridge on the sending sketch ?

Thanks.

LP


#2

Your bridge device is indeed identified by the vPin assigned to the Widget. So if you have a Bridge device on V10, data needs to be send to V10. On the receiving device, you can just use the param.asSomething() to receive he value.


#3

Thanks.

But then, do I have to use two Virtual Pins if I am trying to send to both V3 and V13 ?


#4

Yes, but you still have to send it to V10 to receive it on the other side. You can instantiate multiple Bridges to the same device I think. I’m not sure you can send multiple values with 1 command. I think you can, but I have to try.

I’ll get back to you on that and whip out my test setup :slight_smile:


#5

@Lichtsignaal , yes please mate. I’ve tried sending multiple values on one bridge but have so far failed to get it to work. I’d love to know how you go.


#6

I tried using

WidgetBridge bridgeTemp(V3);
WidgetBridge bridgeHum(V13);

and

bridgeTemp.setAuthToken("…");
bridgeHum.setAuthToken("…");

using the same token…
and

bridgeTemp.virtualWrite(V3,temp_f);
bridgeHum.virtualWrite(V13,humidity);
Blynk.virtualWrite(V3,temp_f);
Blynk.virtualWrite(V13,humidity);

On the receiving side I have:

BLYNK_WRITE(V3) //incoming from Blynk Bridge
{
Blynk.virtualWrite(V3, param.asDouble());
Console.println(param.asDouble());
}

BLYNK_WRITE(V13) //incoming from Blynk Bridge
{
Blynk.virtualWrite(V13, param.asDouble());
Console.println(param.asDouble());
}

But what happens is that I get the same value temperature to both V3 and V13.


#7

@Lichtsignaal,
Actually the bridge identifies another device, not a concrete pin!
So having one bridge (on V10, for example), you can control all pins of another device.
V10 in this case is allocated for a channel to transfer commands to the bridge “target”.


#8

I see that now, I was indeed a bit confused (no coffee yet …). It should work like this then.

-edit-

Documentation states you can send multiple values: http://docs.blynk.cc/#widgets-other-bridge

I seem to remember this was possible, but apparently it is.

And catch them like so:

BLYNK_WRITE(V1) // Widget WRITEs to Virtual Pin V1
{
int x = param[0].asInt(); // getting first value
int y = param[1].asInt(); // getting second value
int z = param[N].asInt(); // getting N value
}


#9

Have you got that to work @Lichtsignaal?


#10

Not yet … I’m trying, but I’m running into some really weird issues. Apparently they are related to the SimpleTimer library. (in conjunction with 0.3.3 beta Blynk and Local server 0.12.6).

When I’m using a timer and try to write V0 it apparently links to GP0 on my ESP. I can’t seem to figure out why, so I went on and removed it and build the following test setup:

ESP-01 with two sliders and two LED’s, sketch:

#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[] = "bleh-bleh-bleh";

WidgetBridge bridgeToB(V31);

int green;
int blue;

void setup()
{
  Serial.begin(9600);
  Serial.println("ESP-01-A");
  Blynk.begin(auth, "Wanda2.4", "bleh-bleh-bleh", "192.168.0.53", 8442);
  
  while (Blynk.connect() == false) {
    // Wait until connected
  }
}

BLYNK_CONNECTED() {
  bridgeToB.setAuthToken("bleh-bleh-bleh");
}

BLYNK_WRITE(V0)
{
  green = param.asInt();
  analogWrite(0, green);
  bridgeToB.virtualWrite(30, green, blue);
}

BLYNK_WRITE(V2)
{
  blue = param.asInt();
  analogWrite(2, blue);
  bridgeToB.virtualWrite(30, green, blue);
}

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

Receiving ESP-01:

#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[] = "bleh-bleh-bleh";

WidgetBridge bridgeToB(V31);

int green;
int blue;

void setup()
{
  Serial.begin(9600);
  Serial.println("ESP-01-A");
  Blynk.begin(auth, "Wanda2.4", "bleh-bleh-bleh", "192.168.0.53", 8442);
  
  while (Blynk.connect() == false) {
    // Wait until connected
  }
}

BLYNK_CONNECTED() {
  bridgeToB.setAuthToken("bleh-bleh-bleh");
}

BLYNK_WRITE(V0)
{
  green = param.asInt();
  analogWrite(0, green);
  bridgeToB.virtualWrite(30, green, blue);
}

BLYNK_WRITE(V2)
{
  blue = param.asInt();
  analogWrite(2, blue);
  bridgeToB.virtualWrite(30, green, blue);
}

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

But now it doesn’t send any values at all anymore to the ESP. Supposedly the 2nd ESP receives the value from the sliders. One of my Value displays 35 (V1) and the other one (V2) displays “(null)”. I’ve added bridge widgets to both, but it doesn’t seem to receive the values.

For bonus points, which movie did we watch last night? :wink:


#11

I fixed a mistake in the code and I actually got the above working.

So this still confused me on the role of the Pin number on the WidgeBridge definition. I has to be the same across both sketches, and it kind of seems pointless to receive a BLINK_WRITE event from the pin, only to send the same value back to the app (Server ?) with a Blynk.virtualWrite on the same pin.

But it is working now.


#12

Hello folks, btw about using bridge, is there any plan to have READ function when using bridge?
As shown in example code at http://docs.blynk.cc, bridges only have Write functions, no Read functions available.
bridge1.digitalWrite(9, HIGH);
bridge1.analogWrite(10, 123);
bridge1.virtualWrite(V1, “hello”);
bridge1.virtualWrite(V2, “value1”, “value2”, “value3”);
It would be very interesting to have READ also.

I was trying to get data from devices running blynk by using blynk_ctrl.py script but seems data get freeze when app is not connected. So not an option for me.


#13

This is using ‘Sync’ feature of Blynk to read the data… It’s not like the Bridge function.
Bridge currently works only for WRITE.

You can set a reverse-bridge to push data in opposite direction. This is verified and works.


#14

So if i wanna to send 3 devices to 4th device i need to revers it am i right ? example:
esp8266 A, esp8266 B, esp8266 C send data to nodemcu A, write command each of esps to nodemcu i tried get rad data from 3 devices to -nodemcu thats where i was mistaking how bridge works :slight_smile: i need try more


#15

@Ronin Please take note of time/date stamps before posting… This is a very old topic.

Bridge is a one way link, so reversing it is really setting up a Bridge on the other side pointing back. Search this forum for more recent references like this…


#16