/**************************************************************
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();
}
Comments