hi. i am using nodemcu esp8226 in my home automation project. problem is that, when wifi off, all switches remain ON as on connection. my code is
#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[] = "d89adaa1a4f742b58ced23d60.........";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "----";
char pass[] = "roora";
const int Relay_1 = 16; //D0
const int Relay_2 = 5; //D1
const int Relay_3 = 4; //D2
const int Relay_4 = 0; //D3
const int Relay_5 = 2; //D4
const int Relay_6 = 14; //D5
const int Relay_7 = 12; //D6
const int Relay_8 = 13; //D7
const int Relay_9 = 15; //D8
void setup()
{
pinMode(Relay_1, OUTPUT);
pinMode(Relay_2, OUTPUT);
pinMode(Relay_3, OUTPUT);
pinMode(Relay_4, OUTPUT);
pinMode(Relay_5, OUTPUT);
pinMode(Relay_6, OUTPUT);
pinMode(Relay_7, OUTPUT);
pinMode(Relay_8, OUTPUT);
pinMode(Relay_9, OUTPUT);
digitalWrite(Relay_1, HIGH);
digitalWrite(Relay_2, HIGH);
digitalWrite(Relay_3, HIGH);
digitalWrite(Relay_4, HIGH);
digitalWrite(Relay_5, HIGH);
digitalWrite(Relay_6, HIGH);
digitalWrite(Relay_7, HIGH);
digitalWrite(Relay_8, HIGH);
// Debug console
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}
/********************** Relay 1 ON/OFF V1 *******************************/
BLYNK_WRITE(V1)
{
int pinValue = param.asInt();
if (pinValue == 1)
{
digitalWrite(Relay_1, HIGH);
Serial.println("Relay 1 On");
}
else if (pinValue == 0)
{
digitalWrite(Relay_1, LOW);
Serial.println("Relay 1 Off");
}
}
/********************** Relay 2 ON/OFF V2 *******************************/
BLYNK_WRITE(V2)
{
int pinValue = param.asInt();
if (pinValue == 1)
{
digitalWrite(Relay_2, HIGH);
Serial.println("Relay 2 On");
}
else if (pinValue == 0)
{
digitalWrite(Relay_2, LOW);
Serial.println("Relay 2 Off");
}
}
/********************** Relay 3 ON/OFF V3 *******************************/
BLYNK_WRITE(V3)
{
int pinValue = param.asInt();
if (pinValue == 1)
{
digitalWrite(Relay_3, HIGH);
Serial.println("Relay 3 On");
}
else if (pinValue == 0)
{
digitalWrite(Relay_3, LOW);
Serial.println("Relay 3 Off");
}
}
/********************** Relay 4 ON/OFF V4 *******************************/
BLYNK_WRITE(V4)
{
int pinValue = param.asInt();
if (pinValue == 1)
{
digitalWrite(Relay_4, HIGH);
Serial.println("Relay 4 On");
}
else if (pinValue == 0)
{
digitalWrite(Relay_4, LOW);
Serial.println("Relay 4 Off");
}
}
/********************** Relay 5 ON/OFF V5 *******************************/
BLYNK_WRITE(V5)
{
int pinValue = param.asInt();
if (pinValue == 1)
{
digitalWrite(Relay_5, HIGH);
Serial.println("Relay 5 On");
}
else if (pinValue == 0)
{
digitalWrite(Relay_5, LOW);
Serial.println("Relay 5 Off");
}
}
/********************** Relay 6 ON/OFF V6 *******************************/
BLYNK_WRITE(V6)
{
int pinValue = param.asInt();
if (pinValue == 1)
{
digitalWrite(Relay_6, HIGH);
Serial.println("Relay 6 On");
}
else if (pinValue == 0)
{
digitalWrite(Relay_6, LOW);
Serial.println("Relay 6 Off");
}
}
/********************** Relay 7 ON/OFF V7 *******************************/
BLYNK_WRITE(V7)
{
int pinValue = param.asInt();
if (pinValue == 1)
{
digitalWrite(Relay_7, HIGH);
Serial.println("Relay 7 On");
}
else if (pinValue == 0)
{
digitalWrite(Relay_7, LOW);
Serial.println("Relay 7 Off");
}
}
/********************** Relay 8 ON/OFF V8 *******************************/
BLYNK_WRITE(V8)
{
int pinValue = param.asInt();
if (pinValue == 1)
{
digitalWrite(Relay_8, HIGH);
Serial.println("Relay 8 On");
}
else if (pinValue == 0)
{
digitalWrite(Relay_8, LOW);
Serial.println("Relay 8 Off");
}
}