sir
kindly note my sketch is
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#define VPIN1 V1 // Virtual Pins for Blynk : Here, declared 4 virtual pins
#define VPIN2 V2
#define VPIN3 V3
#define VPIN4 V4
char auth[] = ;
char ssid[] = "Tenda_1BCB98";
char pass[] = "gagangoel";
void lightOn1(); // Method and variable for Relay1
void lightOff1();
boolean LampState1 = 0;
boolean SwitchReset1 = true;
void lightOn2(); // Method and variable for Relay2
void lightOff2();
boolean LampState2 = 0;
boolean SwitchReset2 = true;
void lightOn3(); // Method and variable for Relay3
void lightOff3();
boolean LampState3 = 0;
boolean SwitchReset3 = true;
void lightOn4(); // Method and variable for Relay4
void lightOff4();
boolean LampState4 = 0;
boolean SwitchReset4 = true;
const int TacSwitch1 = D4; // Connect the Tacswitch to these pins of Nodemcu
const int TacSwitch2 = D7;
const int TacSwitch3 = D6;
const int TacSwitch4 = D7;
const int Relay1 = D0; // Connect the input pins of Relay to these pins of Nodemcu
const int Relay2 = D1;
const int Relay3 = D2;
const int Relay4 = D3;
SimpleTimer timer;
WidgetLED VLED1(V11); // Add LED in Blynk app and set its Pin as V11 (this is indication for relay1
WidgetLED VLED2(V12); // Add LED in Blynk app and set its Pin as V11 (this is indication for relay2
WidgetLED VLED3(V13); // Add LED in Blynk app and set its Pin as V11 (this is indication for relay3
WidgetLED VLED4(V14); // Add LED in Blynk app and set its Pin as V11 (this is indication for relay4
void setup()
{
Serial.begin(115200);
pinMode(Relay1, OUTPUT); // Initializing relays as OUTPUT
pinMode(Relay2, OUTPUT);
pinMode(Relay3, OUTPUT);
pinMode(Relay4, OUTPUT);
pinMode(TacSwitch1, INPUT_PULLUP); // Initializing TacSwitches as Inpull_pullup for reading the
pinMode(TacSwitch2, INPUT_PULLUP);
pinMode(TacSwitch3, INPUT_PULLUP);
pinMode(TacSwitch4, INPUT_PULLUP);
delay(20);
digitalWrite(Relay1, HIGH);
digitalWrite(Relay2, HIGH);
digitalWrite(Relay3, HIGH);
digitalWrite(Relay4, HIGH);
Blynk.config(auth);
timer.setInterval(100, ButtonCheck1);
timer.setInterval(100, ButtonCheck2);
timer.setInterval(100, ButtonCheck3);
timer.setInterval(100, ButtonCheck4);
}
void loop()
{
Blynk.run();
timer.run();
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void ButtonCheck1() {
boolean SwitchState1 = (digitalRead(TacSwitch1));
if (!SwitchState1 && SwitchReset1 == true) {
if (LampState1) {
lightOff1();
} else {
lightOn1();
}
SwitchReset1 = false;
delay(50);
}
else if (SwitchState1) {
SwitchReset1 = true;
}
}
void ToggleRelay1() {
LampState1 = !LampState1;
if (LampState1) {
lightOn1();
}
else lightOff1();
}
void lightOn1() {
digitalWrite(Relay1, LOW);
LampState1 = 1;
Blynk.virtualWrite(VPIN1, HIGH);
VLED1.off();
}
void lightOff1() {
digitalWrite(Relay1, HIGH);
LampState1 = 0;
Blynk.virtualWrite(VPIN1, LOW);
VLED1.on();
}
BLYNK_WRITE(VPIN1) {
int SwitchStatus1 = param.asInt();
if (SwitchStatus1 == 1){
ToggleRelay1();
}
else if (SwitchStatus1){
lightOn1();
}
else lightOff1();
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void ButtonCheck2() {
boolean SwitchState2 = (digitalRead(TacSwitch2));
if (!SwitchState2 && SwitchReset2 == true) {
if (LampState2) {
lightOff2();
} else {
lightOn2();
}
SwitchReset2 = false;
delay(50);
}
else if (SwitchState2) {
SwitchReset2 = true;
}
}
void ToggleRelay2() {
LampState2 = !LampState2;
if (LampState2) {
lightOn2();
}
else lightOff2();
}
void lightOn2() {
digitalWrite(Relay2, LOW);
LampState2 = 1;
Blynk.virtualWrite(VPIN2, HIGH);
VLED2.off();
}
void lightOff2() {
digitalWrite(Relay2, HIGH);
LampState2 = 0;
Blynk.virtualWrite(VPIN2, LOW);
VLED2.on();
}
BLYNK_WRITE(VPIN2) {
int SwitchStatus2 = param.asInt();
if (SwitchStatus2 == 1){
ToggleRelay2();
}
else if (SwitchStatus2){
lightOn2();
}
else lightOff2();
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void ButtonCheck3() {
boolean SwitchState3 = (digitalRead(TacSwitch3));
if (!SwitchState3 && SwitchReset3 == true) {
if (LampState3) {
lightOff3();
} else {
lightOn3();
}
SwitchReset3 = false;
delay(50);
}
else if (SwitchState3) {
SwitchReset3 = true;
}
}
void ToggleRelay3() {
LampState3 = !LampState3;
if (LampState3) {
lightOn3();
}
else lightOff3();
}
void lightOn3() {
digitalWrite(Relay3, LOW);
LampState3 = 1;
Blynk.virtualWrite(VPIN3, HIGH);
VLED3.off();
}
void lightOff3() {
digitalWrite(Relay3, HIGH);
LampState3 = 0;
Blynk.virtualWrite(VPIN3, LOW);
VLED3.on();
}
BLYNK_WRITE(VPIN3) {
int SwitchStatus3 = param.asInt();
if (SwitchStatus3 == 1){
ToggleRelay3();
}
else if (SwitchStatus3){
lightOn3();
}
else lightOff3();
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void ButtonCheck4() {
boolean SwitchState4= (digitalRead(TacSwitch4));
if (!SwitchState4 && SwitchReset4== true) {
if (LampState4) {
lightOff4();
} else {
lightOn4();
}
SwitchReset4 = false;
delay(50);
}
else if (SwitchState4) {
SwitchReset4 = true;
}
}
void ToggleRelay4() {
LampState4 = !LampState4;
if (LampState4) {
lightOn4();
}
else lightOff4();
}
void lightOn4() {
digitalWrite(Relay4, LOW);
LampState4 = 1;
Blynk.virtualWrite(VPIN4, HIGH);
VLED4.off();
}
void lightOff4() {
digitalWrite(Relay4, HIGH);
LampState4 = 0;
Blynk.virtualWrite(VPIN4, LOW);
VLED4.on();
}
BLYNK_WRITE(VPIN4) {
int SwitchStatus4 = param.asInt();
if (SwitchStatus4 == 1){
ToggleRelay4();
}
else if (SwitchStatus4){
lightOn4();
}
else lightOff4();
}
how shall I integrate with with export demo sketch which is
/*************************************************************
This is a DEMO sketch which works with Blynk myPlant app and
showcases how your app made with Blynk can work
You can download free app here:
iOS: https://itunes.apple.com/us/app/blynk-myplant/id1163620518?mt=8
Android: https://play.google.com/store/apps/details?id=cc.blynk.appexport.demo
If you would like to add these features to your product,
please contact Blynk for Businesses:
http://www.blynk.io/
*************************************************************/
#define USE_SPARKFUN_BLYNK_BOARD // Uncomment the board you are using
//#define USE_NODE_MCU_BOARD // Comment out the boards you are not using
//#define USE_WITTY_CLOUD_BOARD
//#define USE_CUSTOM_BOARD // For all other ESP8266-based boards -
// see "Custom board configuration" in Settings.h
#define APP_DEBUG // Comment this out to disable debug prints
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#include "BlynkProvisioning.h"
void setup() {
delay(500);
Serial.begin(115200);
/**************************************************************
*
* Workflow to connect the device to WiFi network.
* Here is how it works:
* 1. At the first start hardware acts as an Access Point and
* broadcasts it's own WiFi.
* 2. myPlant smartphone app connects to this Access Point
* 3. myPlant smartphone app request new Auth Token and passes
* it together with user's WiFi SSID and password
* 4. Hardware saves this information to EEPROM
* 5. Hardware reboots and now connects to user's WiFi Network
* 6. Hardware connects to Blynk Cloud and is ready to work with app
*
* Next time the hardware reboots, it will use the same configuration
* to connect. User can RESET the board and re-initiate provisioning
*
* Explore the Settings.h for parameters
* Read the documentation for more info: http://
*
**************************************************************/
BlynkProvisioning.begin();
example_init(); // Initialize this example
}
void loop() {
// This handles the network and cloud connection
BlynkProvisioning.run();
// Run this example periodic actions
example_run();
}
/**************************************************************
*
* myPlant example App code
*
* The following code simulates plant watering system
*
**************************************************************/
BlynkTimer timer; // Initiating timer to perform repeating event
static int sensorSoilMoisture = 60;
static int sensorAirHumidity = 50;
static int wateringAmount = 5;
static int wateringTimer = -1;
static bool isNotificationSent = false;
// Getting data from "Set watering amount" slider
BLYNK_WRITE(V5) {
wateringAmount = param.asInt();
DEBUG_PRINT(String("Watering amount: ") + wateringAmount);
}
// Getting data from "Start Watering" button
BLYNK_WRITE(V6) {
if (param.asInt() == 1) {
// If watering started -> start simulating watering
timer.enable(wateringTimer);
DEBUG_PRINT("Watering started by user");
} else {
// If watering stopped -> stop simulating watering
timer.disable(wateringTimer);
DEBUG_PRINT("Watering stopped by user");
}
}
// When device starts ->
// sync watering switch button status
// and watering amount level from the cloud (last App value)
BLYNK_CONNECTED() {
Blynk.syncVirtual(V5, V6);
}
// This is a sinusoidal function used for simulations
float sinusoidal(float minv, float maxv, float period) {
float amp = (maxv - minv) / 2.0;
float med = minv + amp;
return med + amp * sin((M_PI * 2 * millis()) / period);
}
// Simulating values jittering
float randomize(float minv, float maxv) {
return float(random(minv * 1000, maxv * 1000)) / 1000;
}
void example_init() {
// Update sensors each 3 seconds
timer.setInterval(3000L, []() {
// Soil moisture
if (sensorSoilMoisture < 33) {
Blynk.virtualWrite(V1, "DRY");
} else if (sensorSoilMoisture > 33) {
Blynk.virtualWrite(V1, "MOIST");
} else {
Blynk.virtualWrite(V1, "WET");
}
float dayPeriod = 3.0 * 60 * 1000;
// Light level
int light = sinusoidal(5, 95, dayPeriod);
if (light < 33) {
Blynk.virtualWrite(V2, "LOW");
} else if (light > 33) {
Blynk.virtualWrite(V2, "GOOD");
} else {
Blynk.virtualWrite(V2, "MED");
}
// Temperature
Blynk.virtualWrite(V3, sinusoidal(18, 23, dayPeriod) + randomize(-1.0, 1.0));
});
// Humidity updates at a different rate (5s)
timer.setInterval(5000L, []() {
sensorAirHumidity += random (-5, +5);
sensorAirHumidity = constrain(sensorAirHumidity, 30, 90);
Blynk.virtualWrite(V4, sensorAirHumidity);
});
// Soil Moisture decreases 3% every second
timer.setInterval(1000L, []() {
sensorSoilMoisture -= 3;
sensorSoilMoisture = constrain(sensorSoilMoisture, 7, 85);
if (sensorSoilMoisture < 20) {
if (isNotificationSent == false) {
Blynk.email("myPlant notification", "Your plant is thirsty!");
isNotificationSent = true;
DEBUG_PRINT("Email notification sent");
}
}
});
// Simulate watering process
wateringTimer = timer.setInterval(1000L, []() {
sensorSoilMoisture += wateringAmount;
sensorSoilMoisture = constrain(sensorSoilMoisture, 7, 85);
if (sensorSoilMoisture > 30) {
isNotificationSent = false;
}
if (sensorSoilMoisture >= 85) {
// Stop watering
timer.disable(wateringTimer);
// Update "Start Watering" button widget state
Blynk.virtualWrite(V6, 0);
DEBUG_PRINT("Watering stopped automatically");
}
});
timer.disable(wateringTimer);
}
void example_run() {
timer.run();
}