GeeksTips.com
Published

Blynk Bridge Example with ESP8266

Getting started with Blynk Bridge - the simplest method to communicate between ESP8266, Arduino or Raspberry Pi.

IntermediateShowcase (no instructions)1 hour2,824
Blynk Bridge Example with ESP8266

Things used in this project

Story

Read more

Code

Blynk Bridge - Communication between ESP8266

Arduino
/**************************************************************
   Blynk Bridge - Communication between ESP8266
   Sketch code for the receiver module (module which is controlled)
   www.geekstips.com
 **************************************************************/
 
#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[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXXXXXXX";
char pass[] = "********";
 
// This code will update the virtual port 5
BLYNK_WRITE(V5) {
  int pinData = param.asInt();
}
 
void setup(){
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
}
 
void loop(){
  Blynk.run();
}

Blynk Bridge - Communication between ESP8266

Arduino
/**************************************************************
   Blynk Bridge - Communication between ESP8266
   Sketch code for the master module (module which will command others)
   www.geekstips.com
 **************************************************************/
#define BLYNK_PRINT Serial
 
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
 
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXXXXXXXXXXXX";
char pass[] = "*************";
 
#define DHTPIN 2 // What digital pin we're connected to
 
//#define DHTTYPE DHT11   // DHT 11
  #define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301
 
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
WidgetBridge bridge1(V1);
 
BLYNK_CONNECTED() {
  // Place the AuthToken of the second hardware here
  bridge1.setAuthToken("tttttttttttttttttttttttttttttttt"); 
}
 
void sendSensor(){
  // get readings from the DHT22 sensor
  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;
  }
 
  // Send command to the second ESP
  // WHEN Temperature IS OVER 28 C
  // in order to open the 220V Relay
  // Also update the VIRTUAL port 5 
  // on the second ESP
  if(t > 28){
     bridge1.digitalWrite(2, 1000);
     bridge1.virtualWrite(V5, 1000); 
  }else{
     bridge1.digitalWrite(2, 0);
     bridge1.virtualWrite(V5, 0); 
  }
 
  // Send temperature and humidity to Blynk App
  // on VIRTUAL ports 5 and 6 in order to 
  // display on Gauge Widget
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
}
 
void setup(){
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  dht.begin();
 
  timer.setInterval(1000L, sendSensor);
}
 
void loop(){
  Blynk.run();
  timer.run();
}

Blynk Bridge - Communication between ESP8266

Arduino
WidgetBridge bridge1(V1);
 
BLYNK_CONNECTED() {
  // Place the AuthToken of the second hardware here
  bridge1.setAuthToken("***********************"); 
}

Blynk Bridge - communication between ESP8266

Arduino
if(t > 28){
     bridge1.digitalWrite(2, 1000);
     bridge1.virtualWrite(V5, 1000); 
}else{
     bridge1.digitalWrite(2, 0);
     bridge1.virtualWrite(V5, 0); 
}

Github

https://github.com/blynkkk/blynk-library/blob/master/examples/Widgets/Bridge/Bridge.ino

Credits

GeeksTips.com

GeeksTips.com

1 project • 11 followers
Technology tutorials, reviews and discussions
Contact

Comments