Blynk bridge with 2 esp8266 i2c lcd temperature sensor dallas

Hi, i need help with my blynk project.
I need to read temperature value from first esp8266 dallas sensor and print value on second esp8266 with i2c lcd, how to use bridge in this case?
Thank you


/* LCD gnd > gnd 
 *     vcc > 5v
 *     sda > sda(D2)
 *     scl > scl(D1)
 *     
 * Dallas gnd > gnd
 *        vcc > 3.3v
 *        data > D5
 *        
 * Relays gnd > gnd
 *         vcc > 5v
 *         in1 > D6
 *         In2 > D8
 * 
 * 
 * 
 *      
 *     **MAIN (first) wemos D1 mini esp8266 with one dallas temp sensor!**
 *           
                                                            CODE! ↓↓↓↓↓↓↓
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓  */


#include <DallasTemperature.h>
#include <OneWire.h> 
#include <Wire.h>   
#include <LiquidCrystal_I2C.h> 
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


#define ONE_WIRE_BUS 14 ///////////// D5

    LiquidCrystal_I2C lcd(0x27,16,2);  
    OneWire oneWire(ONE_WIRE_BUS);  
    DallasTemperature sensors(&oneWire);
    
    char auth[] = "OgtJlfX7BNld";
    char ssid[] = "WiFi";
    char pass[] = "!";


WidgetBridge bridge1(V10);

    
int page_counter=1 ;
//-------Pins-----//
int up = 16;     //D4          //Up button
int down = 13;   //D8         //Down button
 //---------Storage debounce function-----//
boolean current_up = LOW;          
boolean last_up=LOW;            
boolean last_down = LOW;
boolean current_down = LOW;


const int ledPin = D6;
const int btnPin = D3;

BlynkTimer timer;

void checkPhysicalButton();
int ledState = LOW;
int btnState = HIGH;


DeviceAddress probe01 = { 0x28, 0xFF, 0xEE, 0xF4, 0x52, 0x17, 0x04, 0x98  };  // sensor01 address

int sensor01;            
   


BLYNK_CONNECTED() {

  bridge1.setAuthToken("????");


  Blynk.syncVirtual(V2);

  
}

// When App button is pushed - switch the state
BLYNK_WRITE(V2) {
  ledState = param.asInt();
  digitalWrite(ledPin, ledState);
}

void checkPhysicalButton()
{
  if (digitalRead(btnPin) == LOW) {
    // btnState is used to avoid sequential toggles
    if (btnState != LOW) {

      // Toggle LED state
      ledState = !ledState;
      digitalWrite(ledPin, ledState);

      // Update Button Widget
      Blynk.virtualWrite(V2, ledState);
    }
    btnState = LOW;
  } else {
    btnState = HIGH;
  }
}

void setup()  
    {
      Serial.begin(9600);
      Blynk.begin(auth, ssid, pass);


Serial.print("Initializing Temperature Control Library Version ");
  Serial.println(DALLASTEMPLIBVERSION);
  
  sensors.begin(); 
  
  
  sensors.setResolution(probe01, 10);
  
 
 

       pinMode(ledPin, OUTPUT);
  pinMode(btnPin, INPUT_PULLUP);
  digitalWrite(ledPin, ledState);

  // Setup a function to be called every 100 ms
  timer.setInterval(500L, checkPhysicalButton);
  timer.setInterval(500L, myTimerEvent);  
    }
                                                                      
 //---- De-bouncing function for all buttons----//
 boolean debounce(boolean last, int pin)
{
boolean current = digitalRead(pin);
if (last != current)
 {
delay(5);
 current = digitalRead(pin);
 }
return current;
  }

    

void loop() {
sensors.begin();
     
      Blynk.run();
        timer.run();

current_up = debounce(last_up, up);         //Debounce for Up button
current_down = debounce(last_down, down);   //Debounce for Down button

//----Page counter function to move pages----//

//Page Up
    if (last_up== LOW && current_up == HIGH){  //When up button is pressed
      lcd.clear();                     //When page is changed, lcd clear to print new page  
      if(page_counter <3){              //Page counter never higher than 3(total of pages)
      page_counter= page_counter +1;   //Page up
      
      }
      else{
      page_counter= 3;  
      }
  }
  
    last_up = current_up;

//Page Down
    if (last_down== LOW && current_down == HIGH){ //When down button is pressed
      lcd.clear();                     //When page is changed, lcd clear to print new page    
      if(page_counter >1){              //Page counter never lower than 1 (total of pages)
      page_counter= page_counter -1;   //Page down
      
      }
      else{
      page_counter= 1;  
      }
  }
    
    last_down = current_down;

//------- Switch function to write and show what you want---// 
  switch (page_counter) {
   
    case 1:{     //Design of home page 1
      lcd.begin();   
      lcd.backlight(); 
      lcd.setCursor(0, 0);
      lcd.print("Temperatura:");
      lcd.setCursor(0, 1);
      lcd.print(sensors.getTempC(probe01));
      lcd.print((char) 223);
      lcd.print(String("C"));
      
      
    }
    break;

    case 2: { //Design of page 2 
      lcd.begin();   
      lcd.backlight(); 
      lcd.setCursor(0, 0);
      lcd.print("Temperatura2:");
     lcd.setCursor(0, 1);
      //lcd.print(sensors.getTempC(probe02));
      lcd.print((char) 223);
      lcd.print(String("C"));
      
    }
    break;

    case 3: {   //Design of page 3 
      lcd.begin();   
      lcd.backlight(); 
      lcd.setCursor(0, 0);
      lcd.print("Temperatura3:");
      lcd.setCursor(0, 1);
    //  lcd.print(sensors.getTempC(probe03));
      lcd.print((char) 223);
      lcd.print(String("C"));
      
    }
    break;

  }
  }
void myTimerEvent() {
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   
   
  sensors.requestTemperatures();  // Command all devices on bus to read temperature  
  
  Serial.print("Probe 01 temperature is:   ");
  printTemperature(probe01); 
  Serial.println();


 // Serial.print("Probe 02 temperature is:   ");
 // printTemperature(probe02);
 // Serial.println();

 // Serial.print("Probe 03 temperature is:   ");
//  printTemperature(probe03);
 // Serial.println();
 
  sensor01 = sensors.getTempC(probe01);          
 // sensor02 = sensors.getTempC(probe02); 
//  sensor03 = sensors.getTempC(probe03);  

      Blynk.virtualWrite(1, sensor01);         
    //  Blynk.virtualWrite(3, sensor02); 
     // Blynk.virtualWrite(4, sensor03);
}


void printTemperature(DeviceAddress deviceAddress)
{
   
   float tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00) 
   {
    Serial.print("Error getting temperature  ");
   } 
    else
   {
     Serial.print("C: ");
     Serial.print(tempC);
   
    bridge1.virtualWrite(V10,sensors.getTempC(probe01));                                
        
     }
   } 


@Fill please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

/*                       **SECOND Wemos d1 mini WITH 2x dallas temp sensors That need to send temp reading to FIRST MAIN Wemos d1 mini and Display it to case 2 for sensor02 and to case3 for sensor03 and display it on I2c lcd**
*/

#include <DallasTemperature.h>
#include <OneWire.h> 
#include <Wire.h>   
#include <LiquidCrystal_I2C.h> 
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


BlynkTimer timer;

 char auth[] = "";
    char ssid[] = "WiFi";
    char pass[] = "!";

WidgetBridge bridge1(V10);

#define ONE_WIRE_BUS_PIN 14

OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);


//DeviceAddress probe01 = { 0x28, 0xFF, 0xEE, 0xF4, 0x52, 0x17, 0x04, 0x98  };  
DeviceAddress probe02 = { 0x28, 0xFF, 0x51, 0x1D, 0x53, 0x17, 0x04, 0xC9  }; 
DeviceAddress probe03 = { 0x28, 0xFF, 0xCF, 0xC5, 0x52, 0x17, 0x04, 0x6A  }; 

//int sensor01;            
int sensor02;            
int sensor03;            



void setup()   
{
  Serial.begin(9600);  
  Serial.print("Initializing Temperature Control Library Version ");
  Serial.println(DALLASTEMPLIBVERSION);
  
  sensors.begin(); 
  
  
 // sensors.setResolution(probe01, 10);
  sensors.setResolution(probe02, 10);
  sensors.setResolution(probe03, 10);
 
 
  Blynk.begin(auth, ssid, pass);  
  timer.setInterval(1000L, myTimerEvent);  
}

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


 
}

void myTimerEvent() {
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   
   
  sensors.requestTemperatures();  
  
 //Serial.print("Probe 01 temperature is:   ");
  //printTemperature(probe01); 
  //Serial.println();


  Serial.print("Probe 02 temperature is:   ");
  printTemperature(probe02);
  Serial.println();

  Serial.print("Probe 03 temperature is:   ");
  printTemperature(probe03);
  Serial.println();
 
  //sensor01 = sensors.getTempC(probe01);          
  sensor02 = sensors.getTempC(probe02); 
  sensor03 = sensors.getTempC(probe03);  

    //  Blynk.virtualWrite(1, sensor01);         
      Blynk.virtualWrite(3, sensor02); 
      Blynk.virtualWrite(4, sensor03);
}


void printTemperature(DeviceAddress deviceAddress)
{
   
   float tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00) 
   {
    Serial.print("Error getting temperature  ");
   } 
    else
   {
     Serial.print("C: ");
     Serial.print(tempC);
   
   
     }
   
}
   BLYNK_WRITE(V10)                                                      
{
sensor02 = param.asInt();
Serial.println(sensor02);
}

Hi, thank you for your answer!
The idea is to read temperature value(DS18B20) from FIRST wemos d1 mini and display it to app widget and to i2c lcd (menu page 1) which is connected to first d1 mini, and this is working OK

.
Now I need to display temp value from 2x DS18B20 on SECOND d1 mini to FIRST d1 mini which it is connected i2c lcd and display it on menu page 2 and page 3(Case 2, Case 3 in code).
Can you help me with code? I think that bridge widget can help here but I don’t know how to implement it in my code.
Thank you!

If you search the forum for Bridge examples you’ll find some good resources, including one that uses multiple bridges.
You don’t need multiple bridges, as one device (with the two sensors connected) will write the values to two different virtual pins using one bridge Auth code (the Auth code of the other device).

Pete.

So then I only need bride code in my second wemos with 2 dallas that will send data to blynk server?
How to read this data from blynk server and display it on main(first) wemos d1 mini lcd?

I think that if you’d done as I suggested and searched for examples then you’d know that answer to those questions.

Pete.

Sorry, I can’t clearly understand those examples, how bridge work in my case

UPDATE ON MY PROJECT:

I manage to get bridge working(I get temp data showing in serial monitor on main d1 mini) but I can’t get temp data to be written on i2c lcd as Temp2 and Temp3(look images) Lcd show 0.00 as temp value.

When I use lcd.print(sensor02);
I don’t know how to call this function in my case statement.

Here is the code for the MAIN d1 mini with i2c lcd:

/* LCD gnd > gnd 
 *     vcc > 5v
 *     sda > sda(D2)
 *     scl > scl(D1)
 *     
 * Dallas gnd > gnd
 *        vcc > 3.3v
 *        data > D5
 *        
 * Relays gnd > gnd
 *         vcc > 5v
 *         in1 > D6
 *         In2 > D8
 * 
 * 
 * 
 * 
 * 
 * 
 */


#include <DallasTemperature.h>
#include <OneWire.h> 
#include <Wire.h>   
#include <LiquidCrystal_I2C.h> 
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


#define ONE_WIRE_BUS 14 ///////////// D5

    LiquidCrystal_I2C lcd(0x27,16,2);  
    OneWire oneWire(ONE_WIRE_BUS);  
    DallasTemperature sensors(&oneWire);
    
    char auth[] = "Main auth";
    char ssid[] = "WiFi name";
    char pass[] = "passss";


WidgetBridge bridge1(V10);
WidgetBridge bridge2(V11);

    
int page_counter=1 ;
int up = 16;     //D4          //Up button
int down = 13;   //D8         //Down button
 //---------Storage debounce function-----//
 boolean current_up = LOW;          
 boolean last_up=LOW;            
  boolean last_down = LOW;
 boolean current_down = LOW;


const int ledPin = D6;
const int btnPin = D3;

BlynkTimer timer;

void checkPhysicalButton();
int ledState = LOW;
int btnState = HIGH;


DeviceAddress probe01 = { 0x28, 0xFF, 0xEE, 0xF4, 0x52, 0x17, 0x04, 0x98  };  // first dallas

float sensor01; 
float sensor02 = 0;
float sensor03 = 0;


BLYNK_CONNECTED() {

  bridge1.setAuthToken("AUTH TOKEN OF SECOND D1 MINI WITH 2x dallas temp sensors");
  bridge2.setAuthToken("AUTH TOKEN OF SECOND D1 MINI WITH 2x dallas temp sensors");
  
  Blynk.syncVirtual(V2);


  
}
BLYNK_WRITE(V10)
{
float sensor02 = param.asInt();  // TempIn from dallas no. 2
Serial.print("TEMP2: ");
Serial.println(sensor02);
}

BLYNK_WRITE(V11)
{
float sensor03 = param.asInt();  // TempIn from dallas no. 2
Serial.print("TEMP3: ");
 Serial.println(sensor03);
}

// When App button is pushed - switch the state
BLYNK_WRITE(V2) {
  ledState = param.asInt();
  digitalWrite(ledPin, ledState);
}

void checkPhysicalButton()
{
  if (digitalRead(btnPin) == LOW) {
    // btnState is used to avoid sequential toggles
    if (btnState != LOW) {

      // Toggle LED state
      ledState = !ledState;
      digitalWrite(ledPin, ledState);

      // Update Button Widget
      Blynk.virtualWrite(V2, ledState);
    }
    btnState = LOW;
  } else {
    btnState = HIGH;
  }
}

void setup()  
    {
      Serial.begin(9600);
      Blynk.begin(auth, ssid, pass);


  
  sensors.begin(); 
  
  
  sensors.setResolution(probe01, 10);
  
 
 


       pinMode(ledPin, OUTPUT);
  pinMode(btnPin, INPUT_PULLUP);
  digitalWrite(ledPin, ledState);


  timer.setInterval(500L, checkPhysicalButton);
  timer.setInterval(1000L, myTimerEvent);  
    }
                                                                      
                                                                      
                                                                      boolean debounce(boolean last, int pin)
                                                                      {
                                                                      boolean current = digitalRead(pin);
                                                                      if (last != current)
                                                                      {
                                                                      delay(5);
                                                                      current = digitalRead(pin);
                                                                      }
                                                                      return current;
                                                                      }

    


void loop() {
sensors.begin();
     
      Blynk.run();
        timer.run();
current_up = debounce(last_up, up);         //Debounce for Up button
current_down = debounce(last_down, down);   //Debounce for Down button

//----Page counter function to move pages----//

//Page Up
    if (last_up== LOW && current_up == HIGH){  //When up button is pressed
      lcd.clear();                     //When page is changed, lcd clear to print new page  
      if(page_counter <3){              //Page counter never higher than 3(total of pages)
      page_counter= page_counter +1;   //Page up
      
      }
      else{
      page_counter= 3;  
      }
  }
  
    last_up = current_up;

//Page Down
    if (last_down== LOW && current_down == HIGH){ //When down button is pressed
      lcd.clear();                     //When page is changed, lcd clear to print new page    
      if(page_counter >1){              //Page counter never lower than 1 (total of pages)
      page_counter= page_counter -1;   //Page down
      
      }
      else{
      page_counter= 1;  
      }
  }
    
    last_down = current_down;

//------- Switch function to write and show what you want---// 
  switch (page_counter) {
   
    case 1:{     //Design of home page 1
      lcd.begin();   
      lcd.backlight(); 
      lcd.setCursor(0, 0);
      lcd.print("Temp1:");
      lcd.setCursor(0, 1);
      lcd.print(sensors.getTempC(probe01));
      lcd.print((char) 223);
      lcd.print(String("C"));
      
      
    }
    break;

    case 2: { //Design of page 2 
      lcd.begin();   
      lcd.backlight(); 
      lcd.setCursor(0, 0);
      lcd.print("Temp2:");
     lcd.setCursor(0, 1);
   lcd.print(sensor02);       // ????????????????????????????????????????????
      lcd.print((char) 223);
      lcd.print(String("C"));
      
    }
    break;

    case 3: {   //Design of page 3 
       lcd.begin();   
      lcd.backlight(); 
      lcd.setCursor(0, 0);
      lcd.print("Temp3:");
     lcd.setCursor(0, 1);
   lcd.print(sensor03);   // ???????????????????????????????
      lcd.print((char) 223);
      lcd.print(String("C"));
      
    }
    break;

  }
  }  

void myTimerEvent() {  
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   
   
  sensors.requestTemperatures();  
  
  Serial.print("Probe 01 temperature is:   ");
  printTemperature(probe01); 
  Serial.println();


  sensor01 = sensors.getTempC(probe01);   
  


      Blynk.virtualWrite(1, sensor01);         
    
}


void printTemperature(DeviceAddress deviceAddress)
{
   
   float tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00) 
   {
    Serial.print("Error getting temperature  ");
   } 
    else
   {
     Serial.print("C: ");
     Serial.print(tempC);
   
                                       
        
     }
   } 

Code for D1 mini with 2x dallas that send data over bridge:


#include <DallasTemperature.h>
#include <OneWire.h> 
#include <Wire.h>   
#include <LiquidCrystal_I2C.h> 
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


BlynkTimer timer;

 char auth[] = "AUTH TOKEN OF SECOND D1 mini with 2X dallas";
    char ssid[] = "WiFi name";
    char pass[] = "passsssss";

WidgetBridge bridge1(V10);
WidgetBridge bridge2(V11);

#define ONE_WIRE_BUS_PIN 14

OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);



DeviceAddress probe02 = { 0x28, 0xFF, 0x51, 0x1D, 0x53, 0x17, 0x04, 0xC9  };  //sensor02
DeviceAddress probe03 = { 0x28, 0xFF, 0xCF, 0xC5, 0x52, 0x17, 0x04, 0x6A  }; //sensor03

         
float sensor02;            
float sensor03;       

BLYNK_CONNECTED() {
  bridge1.setAuthToken("AUTH TOKEN OF MAIN D1 mini with i2c lcd"); 
   bridge2.setAuthToken("AUTH TOKEN OF MAIN D1 mini with i2c lcd");
}

void setup()   
{
  Serial.begin(9600);  // start serial port to show results
 
  
  sensors.begin(); 
  
 
  sensors.setResolution(probe02, 10);
  sensors.setResolution(probe03, 10);
 
 
  Blynk.begin(auth, ssid, pass);  
  timer.setInterval(1000L, myTimerEvent);  
}

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

      
void myTimerEvent() {
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   
   
  sensors.requestTemperatures();   
  

  Serial.print("Sensor 02 temperature is:   ");
  printTemperature(probe02);
  Serial.println();

  Serial.print("Sensor 03 temperature is:   ");
  printTemperature(probe03);
  Serial.println();
 
         
  sensor02 = sensors.getTempC(probe02); 
  sensor03 = sensors.getTempC(probe03);  

    bridge1.virtualWrite(V10, sensor02);
    bridge2.virtualWrite(V11, sensor03);

     
}


void printTemperature(DeviceAddress deviceAddress)
{
   
   float tempC = sensors.getTempC(deviceAddress);

   if (tempC == -127.00) 
   {
    Serial.print("Error getting temperature  ");
   } 
    else
   {
    Serial.print(tempC);
    Serial.print(" °C");
   
     }
   
}

  




Here is the serial monitor data whitch shows that bridge is working:

First of all, you need to read this:

Then restructure your code so that you have a clean void loop.

You also seem to have some code which is ‘floating’ outside of a function and which seems to make no sense.

Your lack of temperature sensor data for probes 2 and 3 is due to you re-declaring the sensor02 and sensor03 variables within BLYNK_WRITE callback functions (by adding “float” before the variable names), making those values local to those callbacks.

Also, your bridge widget declarations for the MAIN code are unnecessary.

Pete.