Read data from Blynk. Two ESP8266

Hi. I have two ESP8266 devkit 12E. One ESP with si7021 send data to blynk. And i need another ESP with Nextion screen read this data and show on Nextion screen… Is it possible? I dont find a sketch to read from blynk… Thanks.

Yes… a few ways…

Use Blynk on all ESPs, Bridge to share the data, and run the Nextion code on one of the ESPs.

And your ‘missing’ sketches :stuck_out_tongue_winking_eye:

Or use one ESP for everything… Study this and convert for ESP8266 and your sensor…

Otherwise If the ESP for the Nextion is non-Blynk and can use a virtual pin for an extra serial port then you can try EasyTransfer between the Blynk ESP and the Nextion ESP

Thanks. I tryed sketch with DHT sensor and was working. Now i trying sketch with si7021 sensor and is no working…But why? Thanks.

 
#define BLYNK_PRINT Serial 
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

#include <Wire.h>
#include <SI7021.h>

float temp, hum;

bool SI7021_present = true;


#define I2C_SCL 4    //D6 // Barometric Pressure Sensor (BMP085)
#define I2C_SDA 5   //   D7
SI7021 sensor;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).

 char ssid[] = "";
 char pass[] = "";
 char auth[] = "deviceA";  // Put your Auth Token here. (see Step 3 above)
 WidgetBridge bridge1(V1);
SimpleTimer timer;

void setup()
{

  
  sensor.begin(SDA,SCL);
  Wire.begin(I2C_SDA, I2C_SCL);
  Serial.begin(9600); // See the connection status in Serial Monitor
  Blynk.begin(auth, ssid, pass);
 
 timer.setInterval(5000L,sendUptime);

}

void sendUptime()
{
 
float temperature = sensor.getCelsiusHundredths()/100;
float humidity = sensor.getHumidityPercent();
Blynk.virtualWrite(5, temperature); 
Blynk.virtualWrite(6, humidity); // virtual pin

}


  void blynkAnotherDevice() // Here we will send HIGH or LOW once per second
    {
            float humidity = sensor.getHumidityPercent();
            float temperature = sensor.getCelsiusHundredths();
      // Send value to another device
        
           bridge1.virtualWrite(V5, temperature);
           bridge1.virtualWrite(V6, humidity);// Sends 0 value to BLYNK_WRITE(V5) handler on receiving side.
      }

 BLYNK_CONNECTED() {
      bridge1.setAuthToken ("deviceB"); // Place the AuthToken of the second hardware here
      Serial.println ("Sensor1 Linked to Master");

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

DeviceB:

  #define BLYNK_PRINT Serial

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

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

    // Your WiFi credentials.
    // Set password
    char ssid[] = "ASUS72";
    char pass[] = "";

    float TempSensor1;
    float HumiditySensor1;


    BLYNK_WRITE(V5)
    {
      float TempSensor1 = param.asFloat(); // assigning incoming value from pin V5 to a variable
      // You can also use:
      // String i = param.asStr();
      // double d = param.asDouble();
      Serial.print("TempSensor1 is: ");
      Serial.println(TempSensor1);

    }
    BLYNK_WRITE(V6)
    {
      float HumiditySensor1 = param.asFloat(); // assigning incoming value from pin V5 to a variable
      // You can also use:
      // String i = param.asStr();
      // double d = param.asDouble();
      Serial.print("HumiditySensor1 is: ");
      Serial.println(HumiditySensor1);

    }

    void setup()
    {
      
      Serial.begin(9600);

      Blynk.begin(auth, ssid, pass);
      // You can also specify server:
      //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
      //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
    }

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

Define “no working”… one, other or both devices not connecting to server, sender not reading sensor properly, receiver not receiving bridge call (can you test with another bridge call with test data or even App widget to same vPin), neither are making you coffee in the morning?

Both devices are cinnecting to blnyk server but device B no receiving temp and hum… In app Blynk in my phone deviceA show hum and temp and device B no… Thanks:-)

Well, in the sending device (A), double check that you are using the correct AUTH for the receiving (B) device.

1 Like

Yes i have because if i use this sketch deviceB temp and hum receive.

 #define BLYNK_PRINT Serial

    #include <ESP8266WiFi.h>
    #include <BlynkSimpleEsp8266.h>
    #include <SimpleTimer.h>
    //**
    #include <SPI.h>
    #include "DHT.h"
    //**
  #define DHTPIN D4    
    #define DHTTYPE DHT22

    float hum = 0;
    float temp = 0;
    
    char auth[] = "";

    // Your WiFi credentials.
    // Set password to "" for open networks.
    char ssid[] = "ASUS72";
    char pass[] = "";

    // Bridge widget on virtual pin 1
    WidgetBridge bridge1(V1);
    //**
    DHT dht(DHTPIN, DHTTYPE);
    //**



    // Timer for blynking
    SimpleTimer timer;

    void sendUptime()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(5, temp); //virtual pin V10
  Blynk.virtualWrite(6, hum); // virtual pin V11
 

}

    void blynkAnotherDevice() // Here we will send HIGH or LOW once per second
    {
      //**
      float h = dht.readHumidity();
      float t = dht.readTemperature();
      //**
      // Send value to another device
        
           bridge1.virtualWrite(V5, t);
           bridge1.virtualWrite(V6, h);// Sends 0 value to BLYNK_WRITE(V5) handler on receiving side.
      }


    BLYNK_CONNECTED() {
      bridge1.setAuthToken("deviceB"); // Place the AuthToken of the second hardware here
      Serial.println ("Sensor1 Linked to Master");

    }

    void setup()
    {
      // Debug console
      Serial.begin(9600);
       dht.begin();
       timer.setInterval(50000L, getDhtData);
      Blynk.begin(auth, ssid, pass);
      // You can also specify server:
      //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
      //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);

      // Call blynkAnotherDevice every second
      timer.setInterval(1000L, blynkAnotherDevice);
      timer.setInterval(50000L, sendUptime);
    }


    void getDhtData(void)
{
  float tempIni = temp;
  float humIni = hum;
  temp = dht.readTemperature();
  hum = dht.readHumidity();
  if (isnan(hum) || isnan(temp))   // Check if any reads failed and exit early (to try again).
  {
    Serial.println("Failed to read from DHT sensor!");
    temp = tempIni;
    hum = humIni;
    return;
  }
}

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

And in sketch deviceB is good: float TempSensor1;
float HumiditySensor1; ? thanks

Umm, OK… so your issue is resolved then?

No because sketch with sensor si7021, deviceB no receive data from deviceA…But why ? Is possible bridge with library:wire no working? thanks

OK, I am not going to waste my time going though your code line by line… but a bridge1.virtualWrite() is a one-way command that (in this case) emulates a Widget call to a BLYNK_WRITE() function… so very simple actually.

Device A (Bridge Sender) - AUTH = xyzxyzxyz:

WidgetBridge MyBridgeName(vPin); //  Initiating Bridge name and Widget on vPin... I think this widget is NOT required on the sender device but more for a reference and placeholder for the vPin... but I include it anyhow.
BLYNK_CONNECTED() {
  MyBridgeName.setAuthToken("ReceivingDevicesAUTH"); // AUTH of the receiving Device's (B) sketch
}
MyBridgeName.virtualWrite(vPinOfReceiver,value); // Send value to the corresponding * vPinOfReceiver * function on the receiving device

Device B (Bridge Receiver) - AUTH = ReceivingDevicesAUTH:

On the receiving device, all is normal Blynk functions, just waiting for a Widget (from the project with the matching AUTH) or Bridge command (from a sketch set with matching Bridge AUTH) with the corresponding vPin to call (activate) them and possibly supply a value.

… Simple.

2 Likes

Thanks. I delete void blynkAnotherDevice and to the void sendUptime add:

bridge1.virtualWrite(V5,temperature); 
bridge1.virtualWrite(V6,humidity); 

and now deviceB read data…

1 Like

Hi. This sketch was working but now is not. Is possible something wrong in library? I am useing library blynk:0.4.0 and Arduino IDE 1.6.5… Or is problem in Simple timer? Thanks.

The latest Blynk library is 0.5.4 which was released on 6th September, so one should hope that you were using that version when you were working on this project back in October.
You also need to be using the latest ESP core and it wouldn’t hurt to update yourArduino IDE to the letest version either.

I assume that you’re using the Blynk Cloud servers? If not then you need to ensure that your local server is updated to the latest version.
You also need the latest version of the app as well.

Pete.

1 Like

Ok thanks i will try update library, Arduino ide and ESP core. And yes i am use Blynk Cloud.