Bridge don't work on Arduino with ESP8266 wifi module

Hello guys!:grinning:
I am new to the wonderful world of Blynk and I’m doing various experiments and attempts with it.
I tried successfully to use the bridge, installing it on an Arduino with Ethernet shield (called: master) and activating the digital outputs of an Arduino connected with wifi esp8266 (defined: slave).

I can not do the opposite, namely to control the digital outputs on the master, through commands sent from the slave.

I would like, besides being able to activate the relays present on the slave, receive from it the information about a temperature sensor connected to it.

how should I do? what are the commands to get the information, or read values from the slave via the bridge function?

thanks to all in advance.
bye!:grinning:

Hello. You could do same as you did with master.

Master :

//send command to slave
bridge.virtualWrite(V1, ..);

//read command from slave
BLYNK_WRITE(V1) {
}

Slave :

//send command to master
bridge.virtualWrite(V1, ..);

//read command from master
BLYNK_WRITE(V1) {
}

Hello,
thanks for the reply!

I do not understand how to read values from the slave, if I have a temperature sensor installed on the slave, how do I display it on the main screen of the app on my iphone.

for the slave, all started with the sketch example: ESP8266_Shield_HardSer and noticed that by configuring the bridge function on it, although I have no problem compiling, I can not “control” channel on the master, which on the contrary works perfectly.

waiting for your reply, also place the code I’m using for the master and the slave.

thanks, bye.

MASTER CODE:

//#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>
#include <DHT.h>

DHT dht;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "MASTER AUTH";
WidgetBridge bridge1(V11);
WidgetBridge bridge2(V2);
SimpleTimer timer; //definisco il nome del timer in: "timer"

void setup()
{
  //Serial.begin(9600);
  Blynk.begin(auth);
  while (Blynk.connect() == false) {
    // Wait until connected
  }
  bridge1.setAuthToken("BRIDGE1 AUTH");
  bridge2.setAuthToken("BRIDGE2 AUTH <-- SLAVE");
  dht.setup(2); // setta il pin lettura dati del sensore in data pin D2
  timer.setInterval(2000L, led); //setta intervallo lettura timer
  timer.setInterval(350000L, dht22); //setta intervallo lettura timer
  //timer.setInterval(2000L, blynkAnotherDevice);
  // You can also specify server.
  // For more options, see BoardsAndShields/Arduino_Ethernet_Manual example
  //Blynk.begin(auth, "your_server.com", 8442);
  //Blynk.begin(auth, IPAddress(192,168,1,100), 8888);
}

  BLYNK_WRITE(11)
  {
    if (param.asInt()) {
        bridge1.digitalWrite(7, HIGH);
    } else {
        bridge1.digitalWrite(7, LOW);
    }
  }
  BLYNK_WRITE(12)
  {
    if (param.asInt()) {
        bridge2.digitalWrite(4, HIGH);
    } else {
        bridge2.digitalWrite(4, LOW);
    }
  }
  BLYNK_WRITE(13)
  {
    if (param.asInt()) {
        bridge2.digitalWrite(5, HIGH);
    } else {
        bridge2.digitalWrite(5, LOW);
    }
  }
  BLYNK_WRITE(14)
  {
    if (param.asInt()) {
        bridge2.digitalWrite(6, HIGH);
    } else {
        bridge2.digitalWrite(6, LOW);
    }
  }
  BLYNK_WRITE(15)
  {
    if (param.asInt()) {
        bridge2.digitalWrite(7, HIGH);
    } else {
        bridge2.digitalWrite(7, LOW);
    }
  }
  
//void blynkAnotherDevice()
  

void led()
 {
   if (digitalRead(4) == HIGH){
     Blynk.virtualWrite(V2, HIGH);
     Blynk.virtualWrite(V1, LOW);
   }
   else{
     Blynk.virtualWrite(V2, LOW);
     Blynk.virtualWrite(V1, HIGH);
   }
   if (digitalRead(5) == HIGH){
     Blynk.virtualWrite(V6, HIGH);
     Blynk.virtualWrite(V3, LOW);
   }
   else{
     Blynk.virtualWrite(V3, HIGH);
     Blynk.virtualWrite(V6, LOW);
   }
   if (digitalRead(6) == HIGH){
     Blynk.virtualWrite(V8, HIGH);
     Blynk.virtualWrite(V7, LOW);
   }
   else{
     Blynk.virtualWrite(V7, HIGH);
     Blynk.virtualWrite(V8, LOW);
   }
   if (digitalRead(7) == HIGH){
     Blynk.virtualWrite(V10, HIGH);
     Blynk.virtualWrite(V9, LOW);
   }
   else{
     Blynk.virtualWrite(V9, HIGH);
     Blynk.virtualWrite(V10, LOW);
   }
}

void dht22()
{
 delay(dht.getMinimumSamplingPeriod());
 float humidity = dht.getHumidity();
 float temperature = dht.getTemperature();
 Blynk.virtualWrite(V5, humidity);
 Blynk.virtualWrite(V4, temperature);
}

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

SLAVE CODE:

//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SimpleTimer.h>
// Set ESP8266 Serial object
#define EspSerial Serial
#define ONE_WIRE_BUS 8

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
ESP8266 wifi(EspSerial);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "SLAVE AUTH";
WidgetBridge bridge1(V0);
SimpleTimer timer;

void setup()
{
  // Set console baud rate
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  /*Blynk.begin(auth);
  while (Blynk.connect() == false) {
    // Wait until connected
  }*/
  bridge1.setAuthToken("MASTER AUTH");
  EspSerial.begin(115200);
  delay(10);
  sensors.begin();
  Blynk.begin(auth, wifi, "SSID", "PASS");
  timer.setInterval(10000L, temp);
  timer.setInterval(5000L, led);
}

void temp()
{
  sensors.requestTemperatures();
  float temperature = sensors.getTempCByIndex(0);
  Blynk.virtualWrite(V0, temperature);
  //bridge1.virtualWrite(V16, temperature);
}
void led()
{
  if (digitalRead(4) == HIGH){
     Blynk.virtualWrite(V1, HIGH);
     bridge1.digitalWrite(4, HIGH);
   }
   else{
     Blynk.virtualWrite(V1, LOW);
     bridge1.digitalWrite(4, LOW);
   }
} 
void loop()
{
  Blynk.run();
  timer.run();
}

I do not understand how to read values from the slave, if I have a temperature sensor installed on the slave, how do I display it on the main screen of the app on my iphone.

How does that related with bridge? Bridge is just for device-device communication. No app. involved.

If you need to display value on app. screen you need to add widget, select pin, let’s say V1 and on hardware side do Blynk.virtualWrite(V1, temp);

Here is doc.

I think he means he wants to display the Temperature on the Dashboard of the Master project. So the data has to be send from Slave to Master and Master has to display it.

You need to do bridgeMaster.virtualWrite(V31, Temperature); on the slave device and on the master do something on pin V31, or just simply attach that to a Value display on the dashboard of your Master device.

(For clarity, I’d recommend renaming the Bridge widget on both devices to include a name to refer to the device they are connecting too, e.g. WidgetBridge bridgeSlave(V0); // Bridge to slave node and vice versa)

1 Like

Hello Lichtsignal,
thanks for the reply!
that’s right, I want to do just what you say, this test I did, writing the code on the slave just as you indicated and putting a display connected to pin V16 on the dashboard of the master, but I see nothing!
the same temperature information sent to the dashboard of the slave works well.
what I should have realized that it is in the library that I’m using for the slave, you are missing something to make it work properly with the bridge function.
in my previous post you can see from the code, the libraries used.
I hope I have expressed myself well,
bay!

And then something else, I think you can only sent integers, you are trying to send a float with your bridge, try this on the slave unit:

bridge1.virtualWrite(V16, (int)temperature);

This is btw how I convert my values and send them to a Value display:

int tempHumid = (int)h;
  int tempTemp  = (int)c;
  
  String humid  = (String)tempHumid;
  String temp   = (String)tempTemp;
  
  humid += "%";
  temp += "°C";
  
  Blynk.virtualWrite(V13, humid);
  Blynk.virtualWrite(V14, temp);

Also, you don’t need the dallas libraries on you master device. You are only sending data, unless there is also a sensor connected to the master…

1 Like

@Lichtsignaal Thankyou so much for the hints on how to send strings to the Blynk displays and how to add the symbols to the strings.

its not work. please, show full of simple example. and how about used same name virtuals pin between master and slave?

к сожалению, предложенная структура не работает. Я со slave через bridgemaster.virtualwrite(v11, temp) посылаю значение температуры в виртуальный пин 11, но процедура BLYNK_WRITE(V11) не запускается на master (проверено). Может представите какой-нибудь работающий пример, чтобы любое значение со slave передавалось на master и выполнялось к примеру вывод в приложение.
PS почему бы не добавить в bridge функции virtualread, digitalread и analogread. тогда было бы легко интегрировать разные slave, не модифицируя каждый раз программу, считывать значения с датчиков и перевести основную логику в master

Hi. I notice that your project shared some similarity with mine. If its possible, I need your help.
I’m trying to make the arduino communicate.

The operation:
When the widget button is pressed, first arduino(server) receive the input (and make servo move) then send the input to the second arduino(client) to move servo as well.
Here i’m using 2 arduino uno, 2 esp8266 wifi shield.

In your opinion, can I use bridge for my project?
I’m sorry for troubling you. Thank you in advance

This is an old topic and much changes in months let alone over a year. If you have an issue, please create your own Topic with appropriate title and details. Thank you.

EDIT - I see you already did… But please do not ask the same question in other topics… gets too spread out and confusing otherwise… Thanks again.