BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       👉 SKETCH BUILDER

Multi devices eventor

No matter, sensor and relay on same devices is easy to do and i know how to do that.

I’m here for learn so i learn bridge

It’s for montoring fan : on slave i’ve T° sensor, if T° is more than 30 fan is on, else is less than 29 fan OFF

T° on slave, fan relay on master

I’ve create new project who’s named bridge with two devices : master and slave

I know, but i don’t know witch Template ID, Token and devices name i’ve to put here

I’m looking for this sketch exemple : Blynk Example Browser

Personally, I’d ignore that example. It uses the Bridge widget, and I’m not even sure it ever worked as designed.

Read some of these topics by @Gunner

https://community.blynk.cc/search?q=@gunner%20bridge

Also, if you’re just wanting to learn how Bridge works then I’d suggest sending something simple, like uptime in seconds, from one device to the other.

Pete.

So now bridge work ! Thanks !

Following C++ Blynk (Legacy) - Code Examples for Basic Tasks - #22 by Gunner

Hi !

My bridge is working, now i’ve problem. How i can read Vpin value coming from bridge to start function.

Here is my sketch in void relais i want to read V44 who’s humidity value from device2

#define BLYNK_PRINT Serial

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

char auth[] = "xx";
char ssid[] = "xxx";
char pass[] = "xxxx";

BlynkTimer timer;

//
WidgetBridge bridge1(V1);

//
int minRange = 70;
int maxRange = 80;

void setup()
{
  // Debug console
  Serial.begin(9600);


  Blynk.begin(auth, ssid, pass, IPAddress(10, 3, 141, 1), 8080);
  digitalWrite(2 , LOW);
  delay(1000L);
  digitalWrite(2 , HIGH);
}

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

BLYNK_WRITE(V43) { 
  Blynk.virtualWrite(V43, param.asFloat());
}

BLYNK_WRITE(V44) { 
  Blynk.virtualWrite(V44, param.asFloat());
}

void relais ()

{

  if (V44 > minRange)
  {
    digitalWrite(2, HIGH);
  }

  else
  {
    digitalWrite(2, LOW);
  }
}

Thanks

Let’s keep all of your Bridge experiments in one place, rather than creating a parallel discussion in a different topic.

I have no idea what this code is meant to achieve, and it’s doing some very odd things like this…

However, as I said earlier…

Pete.

This is input from sending device. As Gunner on his post : C++ Blynk (Legacy) - Code Examples for Basic Tasks - #22 by Gunner

With gauge on receiving devices i’ve value ( on V44 and V43 ) from sender

Sending sketch :

#define BLYNK_PRINT Serial

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

#define DHTPIN 2          // What digital pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).

char auth[] = "IlcMe5hpdqwqpsoisIObIkhtNuRRq_k9";


char ssid[] = "indoor";
char pass[] = "indoorwifi";


BlynkTimer timer;

 float h = dht.readHumidity();
  float t = dht.readTemperature();
WidgetBridge bridge1(V1);

void setup()
{
  // Debug console
  Serial.begin(9600);


  Blynk.begin(auth, ssid, pass, IPAddress(10, 3, 141, 1), 8080);

  dht.begin();

  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);

 
}

BLYNK_CONNECTED() {
  bridge1.setAuthToken("VsfeTTqiW4sizahXIBbECZSp0NohKEm_"); // Token of the hardware B
}

void loop()
{
  Blynk.run();
  timer.run();
}
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V20, h);
  Blynk.virtualWrite(V21, t);
   bridge1.virtualWrite(V43, t);  
  bridge1.virtualWrite(V44, h);  
}

Receiving sketch :

#define BLYNK_PRINT Serial

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

char auth[] = "VsfeTTqiW4sizahXIBbECZSp0NohKEm_";
char ssid[] = "indoor";
char pass[] = "indoorwifi";

BlynkTimer timer;

//
WidgetBridge bridge1(V1);

//
int minRange = 70;
int maxRange = 80;

void setup()
{
  // Debug console
  Serial.begin(9600);


  Blynk.begin(auth, ssid, pass, IPAddress(10, 3, 141, 1), 8080);
  digitalWrite(2 , LOW);
  delay(1000L);
  digitalWrite(2 , HIGH);
}

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

BLYNK_WRITE(V43) { 
  Blynk.virtualWrite(V43, param.asFloat());
}

BLYNK_WRITE(V44) { 
  Blynk.virtualWrite(V44, param.asFloat());
}

void relais ()

{

  if (V44 > minRange)
  {
    digitalWrite(2, HIGH);
  }

  else
  {
    digitalWrite(2, LOW);
  }
}

And if you read that post carefully you’ll see that it’s for a bi-directional Bridge, where both devices are both sending and receiving via the Bridge, which isn’t what you said you were trying to achieve.

Change this…

So that you’re serial printing the value that is being recieved on V43 rather than doing a Blynk.virtualWrite with it.

If you’re expecting this to do something with the data received on pin V44 then you’re mistaken…

That’s not how you access the data that is received on a virtual pin.
Read the “using virtual pins to control physical devices” tutorial that I linked to in post #14 for more info.

Pete.

Wich can more can less, step by step, first one directional after bi directional. I don’t know how to change this

I receive two value humidity from V44 and temperature from V43 ineed both
I’s working with gauge attached to V44 and V33.
I don’t understand what you mean

I know, that’s why i ask for…

Ok i’ve removed

BLYNK_WRITE(V43) { 
  Blynk.virtualWrite(V43, param.asFloat());
}

BLYNK_WRITE(V44) { 
  Blynk.virtualWrite(V44, param.asFloat());
}

from recieve devices

as far as I know, when perform a virtualWrite with bridge, second board ( receiver ) will need to process the incoming command, It can be done by using this handler on the second board

    BLYNK_WRITE(V5){
    int pinData = param.asInt(); // pinData variable will store value that came via Bridge
    //    }

Hi John

It’s working without this, i received value. Know i’m just looking for how i’ve to call this value

You mean how to use it outside the function right ?

Yes i think.

void relais ()

{

  if (V44 > minRange)
  {
    digitalWrite(2, HIGH);
  }

  else
  {
    digitalWrite(2, LOW);
  }
}

I know if (V44... is wrong way but i don’t know how to do, for have V44 value.

With int i think, but int what ?

Add a global variable and name it what ever you want for example

int pinData;

then you can use

BLYNK_WRITE(V5){
    pinData = param.asInt();

after that you will be able to use outside the function
Like this


  if (pinData > minRange)
  {
    digitalWrite(2, HIGH);
  }

  else
  {
    digitalWrite(2, LOW);
  }
}

And I don’t know what this comment means, so it’s difficult to provide a sensible response.

There is no point in using Bridge on Legacy to send data to a gage widget. legacy allows the gauge widget to be attached to the datastream of the sending device, so bridge is redundant in that scenario.
What you are (I think) trying to achieve is to send temperature and humidity data from one device to another, so that the device which receives the data can apply some logical tests to it and take action - such as turning on a relay - if certain criteria are met.
The first step in achieving this is to visualise in the serial monitor of your receiving device the values that are being received. Note that I’ve said the serial monitor of the receiving device, NOT a widget in the Blynk app. So, you should put a serial print command inside the BLYNK_WRITE(vPin) commands that are being used to receive the data from te sending device.

Once you’ve proven that you are receiving the values that are being sent by the other device then you can write your logical test.
This should probably be done inside the BLYNK_WRITE(vPin) commands, or in a timed function which uses the values that have been received in the BLYNK_WRITE(vPin) commands. If you do the latter then you’ll need to use global variables.

Pete.

So, ok with this code i receive humidity value from deveice2 on serial monitor.
But It dont activate relay on D4 pin…

   #define BLYNK_PRINT Serial

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

char auth[] = "xx";
char ssid[] = "xx";
char pass[] = "xx";

BlynkTimer timer;

//
WidgetBridge bridge1(V1);

//
int minRange = 70;
int maxRange = 80;
int h;

BLYNK_WRITE(V44) {
  h = param.asInt();
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass, IPAddress(10, 3, 141, 1), 8080);
  digitalWrite (2 , OUTPUT);
  digitalWrite (2 , LOW);
  timer.setInterval(1000L, relay);
}

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



void relay ()

{
  Serial.println(h);

  if (h > 70)
  {
    digitalWrite(2, HIGH);
  }

  else
  {
    digitalWrite(2, LOW);
  }
}

Should be a pinMode statement.

Pete.

Ok now all is working !

Last think, why the low and high state are reversed ? ( LOW make me relay on and HIGH make ma relay off )

It’s possible to fix it ?

That’s because you’re using an active low relay. to solve this, all you have to do is change high to low and low to high, like this

if (h > 70)
  {
    digitalWrite(2, LOW);
  }

  else
  {
    digitalWrite(2, HIGH);
  }
}

Yep, i know. I was hoping there’s other solution.

Thanks @John93 and thanks @PeteKnight for your help !

1 Like