Nodemcu stays in connect but it get divice offline within a day

Just search the forum for Blynk.config and Blynk.connect, or read the Legacy documentation.

Pete.

Sir, I have changed the coding according to your saying and Blynk.config, Blynk.connect and the Legacy documentation.
Please say it whether it is correct or wrong.I appreciate your help.

#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial

//#define BLYNK_MAX_SENDBYTES 128
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char ssid[] = "user name ";
char pass[] = "password";

char auth[] = "auth token";

#define BLYNK_PRINT Serial


int val = 0; 
int pirState;
int x = 0;
WidgetLCD lcd(V1);
WidgetLCD lcd2(V5);
WidgetLCD lcd3(V7);
int ReCnctFlag;  // Reconnection Flag
int ReCnctCount = 0;  
BlynkTimer timer;

BLYNK_WRITE(V0)   
{

  if(param.asInt() == 0){
    pinMode(D0, LOW);
      lcd.print(0, 0, "SWITCH 01 OFF"); 
  }else{
     pinMode(D0, HIGH);
      lcd.print(0, 0, "SWITCH 01 ONN"); 
  }
   
}

BLYNK_WRITE(V2)   
{

  if(param.asInt() == 0){
    pinMode(D1, LOW);
     lcd.print(0, 1, "SWITCH 02 OFF"); 
  }else{
     pinMode(D1, HIGH);
      lcd.print(0, 1, "SWITCH 02 ONN"); 
  }
   
}

BLYNK_WRITE(V3)   
{

  if(param.asInt() == 0){
    pinMode(D5, LOW);
  lcd2.print(0, 0, "SWITCH 03 OFF"); 
  }else{
     pinMode(D5, HIGH);
 lcd2.print(0, 0, "SWITCH 03 ONN"); 
  }
   
}

#define pirPin D4               
int pirValue;   
char replybuffer[255];             
int pinValue;  
SoftwareSerial sim(10, 11);
int _timeout;
String _buffer;

BLYNK_WRITE(V4)   
{
  
  if(param.asInt() == 0){
    pinMode(D3, LOW);
     lcd2.print(0, 1, "SWITCH 04 OFF"); 
  }else{
     pinMode(D3, HIGH);
      lcd2.print(0, 1, "SWITCH 04 ONN"); 
  }
   
}

BLYNK_WRITE(V6)   
{
 pinValue = param.asInt();    
  if(param.asInt() == 0){
    lcd3.clear();
     lcd3.print(0, 1, "HUMAN OFF"); 
  }else{
      lcd3.print(0, 1, "HUMAN ONN"); 
  }
   
}

BLYNK_CONNECTED(){
  Blynk.syncAll();  
}

int calibrationTime = 30;
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int PIRValue = 0;

void setup() { 
  
   Serial.begin(9600);
   
  _buffer.reserve(50);
  Serial.println("System Started...");


  pinMode(D0, OUTPUT);
  pinMode(D1, OUTPUT);
  pinMode(D5, OUTPUT);
  pinMode(D3, OUTPUT);

  pinMode(D0, LOW);
  pinMode(D1, LOW);
  pinMode(D5, LOW);
  pinMode(D3, LOW);
 
  pinMode(pirPin, INPUT_PULLUP);
  
   Blynk.connectWiFi(ssid, pass);  // Blynk WiFi setup
  Blynk.config(auth, "blynk-cloud.com", 8080);
  Blynk.connect();
//  Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8080);

  lcd.clear(); 

  timer.setInterval(2500L, notifiaction);
}

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

void notifiaction()
{
  if(pinValue){
    int sensor = digitalRead(pirPin);

    if (sensor == 1) {
      Serial.println("WARNING! Please check your security system");
         Blynk.notify("WARNING! Please check your security system");  
      lcd3.print(0, 0, "MOTION DETACTED.."); 
    }else{
       lcd3.print(0, 0, "MOTION  NOT DETACTED.."); 
    }
  }
 
}```

```⸮⸮System Started...
[65] Connecting to Aflal
[4294] Connected to WiFi
[4294] IP: 192.168.162.48
[4294] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on ESP8266

[4372] Connecting to blynk-cloud.com:8080
[4787] Ready (ping: 168ms).```

You had a working Wi-Fi connection system in your original sketch. Re-instate that snd remove this.

Pete.

Hi sir i changed wifi coding
Please check it sir
Please say it whether it is correct or wrong.I appreciate your help.

#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial

//#define BLYNK_MAX_SENDBYTES 128
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char ssid[] = "xxxxxx";
char pass[] = "xxxxxxxxx";

char auth[] = "xxxxxxxxxc";

#define BLYNK_PRINT Serial


int val = 0; 
int pirState;
int x = 0;
WidgetLCD lcd(V1);
WidgetLCD lcd2(V5);
WidgetLCD lcd3(V7);
int ReCnctFlag;  // Reconnection Flag
int ReCnctCount = 0;  
BlynkTimer timer;

BLYNK_WRITE(V0)   
{

  if(param.asInt() == 0){
    pinMode(D0, LOW);
      lcd.print(0, 0, "SWITCH 01 OFF"); 
  }else{
     pinMode(D0, HIGH);
      lcd.print(0, 0, "SWITCH 01 ONN"); 
  }
   
}

BLYNK_WRITE(V2)   
{

  if(param.asInt() == 0){
    pinMode(D1, LOW);
     lcd.print(0, 1, "SWITCH 02 OFF"); 
  }else{
     pinMode(D1, HIGH);
      lcd.print(0, 1, "SWITCH 02 ONN"); 
  }
   
}

BLYNK_WRITE(V3)   
{

  if(param.asInt() == 0){
    pinMode(D5, LOW);
  lcd2.print(0, 0, "SWITCH 03 OFF"); 
  }else{
     pinMode(D5, HIGH);
 lcd2.print(0, 0, "SWITCH 03 ONN"); 
  }
   
}

#define pirPin D4               
int pirValue;   
char replybuffer[255];             
int pinValue;  
SoftwareSerial sim(10, 11);
int _timeout;
String _buffer;

BLYNK_WRITE(V4)   
{
  
  if(param.asInt() == 0){
    pinMode(D3, LOW);
     lcd2.print(0, 1, "SWITCH 04 OFF"); 
  }else{
     pinMode(D3, HIGH);
      lcd2.print(0, 1, "SWITCH 04 ONN"); 
  }
   
}

BLYNK_WRITE(V6)   
{
 pinValue = param.asInt();    
  if(param.asInt() == 0){
    lcd3.clear();
     lcd3.print(0, 1, "HUMAN OFF"); 
  }else{
      lcd3.print(0, 1, "HUMAN ONN"); 
  }
   
}

BLYNK_CONNECTED(){
  Blynk.syncAll();  
}

int calibrationTime = 30;
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int PIRValue = 0;

void initWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);
  Serial.print("Connecting to WiFi ..");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(1000);
  }
  Serial.println(WiFi.localIP());
  //The ESP8266 tries to reconnect automatically when the connection is lost
  WiFi.setAutoReconnect(true);
  WiFi.persistent(true);
}

void setup() { 
  
   Serial.begin(9600);
   
  _buffer.reserve(50);
  Serial.println("System Started...");


  pinMode(D0, OUTPUT);
  pinMode(D1, OUTPUT);
  pinMode(D5, OUTPUT);
  pinMode(D3, OUTPUT);

  pinMode(D0, LOW);
  pinMode(D1, LOW);
  pinMode(D5, LOW);
  pinMode(D3, LOW);
 
  pinMode(pirPin, INPUT_PULLUP);
  
  initWiFi();  // Blynk WiFi setup
  Blynk.config(auth, "blynk-cloud.com", 8080);
  Blynk.connect();
//  Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8080);

  lcd.clear(); 

  timer.setInterval(2500L, notifiaction);
}

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

void notifiaction()
{
  if(pinValue){
    int sensor = digitalRead(pirPin);

    if (sensor == 1) {
      Serial.println("WARNING! Please check your security system");
         Blynk.notify("WARNING! Please check your security system");  
      lcd3.print(0, 0, "MOTION DETACTED.."); 
    }else{
       lcd3.print(0, 0, "MOTION  NOT DETACTED.."); 
    }
  }
 
}/```

That looks better.
Now I’d add a timer that checks if the WiFi is connected, and if Blynk is connected, and if not then do a re-connection, rather than a restart like you had originally.
You should also introduce a flag so that you only send one notification for each motion detection event, to avoid spamming yourself with notifications and to avoid exceeding the 1 notification every 5 second limit.

Pete.

I changed the coding as per you said .
.I appreciate your help.

#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial

//#define BLYNK_MAX_SENDBYTES 128
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char ssid[] = "xxxxxxxx";
char pass[] = "xxxxxxxx";

char auth[] = "xxxxxxxxxxxxxxx";

#define BLYNK_PRINT Serial


int val = 0; 
int pirState;
int x = 0;
WidgetLCD lcd(V1);
WidgetLCD lcd2(V5);
WidgetLCD lcd3(V7);
int ReCnctFlag;  // Reconnection Flag
int ReCnctCount = 0;  
BlynkTimer timer;

BLYNK_WRITE(V0)   
{

  if(param.asInt() == 0){
    pinMode(D0, LOW);
      lcd.print(0, 0, "SWITCH 01 OFF"); 
  }else{
     pinMode(D0, HIGH);
      lcd.print(0, 0, "SWITCH 01 ONN"); 
  }
   
}

BLYNK_WRITE(V2)   
{

  if(param.asInt() == 0){
    pinMode(D1, LOW);
     lcd.print(0, 1, "SWITCH 02 OFF"); 
  }else{
     pinMode(D1, HIGH);
      lcd.print(0, 1, "SWITCH 02 ONN"); 
  }
   
}

BLYNK_WRITE(V3)   
{

  if(param.asInt() == 0){
    pinMode(D5, LOW);
  lcd2.print(0, 0, "SWITCH 03 OFF"); 
  }else{
     pinMode(D5, HIGH);
 lcd2.print(0, 0, "SWITCH 03 ONN"); 
  }
   
}

#define pirPin D4               
int pirValue;   
char replybuffer[255];             
int pinValue;  
SoftwareSerial sim(10, 11);
int _timeout;
String _buffer;

BLYNK_WRITE(V4)   
{
  
  if(param.asInt() == 0){
    pinMode(D3, LOW);
     lcd2.print(0, 1, "SWITCH 04 OFF"); 
  }else{
     pinMode(D3, HIGH);
      lcd2.print(0, 1, "SWITCH 04 ONN"); 
  }
   
}

BLYNK_WRITE(V6)   
{
 pinValue = param.asInt();    
  if(param.asInt() == 0){
    lcd3.clear();
     lcd3.print(0, 1, "HUMAN OFF"); 
  }else{
      lcd3.print(0, 1, "HUMAN ONN"); 
  }
   
}

BLYNK_CONNECTED(){
  Blynk.syncAll();  
}

int calibrationTime = 30;
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int PIRValue = 0;
int PIRflag = 0;

void initWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);
  Serial.print("Connecting to WiFi ..");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(1000);
  }
  Serial.println(WiFi.localIP());
  //The ESP8266 tries to reconnect automatically when the connection is lost
  WiFi.setAutoReconnect(true);
  WiFi.persistent(true);
}

void setup() { 
  
   Serial.begin(9600);
   
  _buffer.reserve(50);
  Serial.println("System Started...");


  pinMode(D0, OUTPUT);
  pinMode(D1, OUTPUT);
  pinMode(D5, OUTPUT);
  pinMode(D3, OUTPUT);

  pinMode(D0, LOW);
  pinMode(D1, LOW);
  pinMode(D5, LOW);
  pinMode(D3, LOW);
 
  pinMode(pirPin, INPUT_PULLUP);
  
  initWiFi();  // Blynk WiFi setup
  Blynk.config(auth, "blynk-cloud.com", 8080);
  Blynk.connect();
//  Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8080);

  lcd.clear(); 

  timer.setInterval(2500L, notifiaction);
}

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

void notifiaction()
{
  if(pinValue){
    int sensor = digitalRead(pirPin);

    if (sensor == 1) {
      if(PIRflag == 0){
        Serial.println("WARNING! Please check your security system");
         Blynk.notify("WARNING! Please check your security system");  
      lcd3.print(0, 0, "MOTION DETACTED.."); 
      PIRflag = 1;
      }
    }else{
       lcd3.print(0, 0, "MOTION  NOT DETACTED.."); 
        PIRflag = 0;
    }
  }
 
}```

Really? Maybe you posted the wrong code?

Pete.

Can you point out what’s wrong on here ?

Where is this in the sketch you posted?

Pete.

Sir, I cannot understand what you are saying accordin to this post.
Can you please tell in a way that i could easily understand? I really appreciate your help.

Go back to the original code you posted.
Look at the void loop and locate the part that checks if there is a WiFi connection and restarts the device of not.

Put this on a function, remove the restart part and replace it with a reconnection call, and do the same with a check to see if Blynk is connected.
Call this function with a timer.

Pete.

1 Like

Is it okay now? Are you telling me to put in this method?

#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial

//#define BLYNK_MAX_SENDBYTES 128
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char ssid[] = "xxxxxx";
char pass[] = "xxxxx";

char auth[] = "xxxxxxxxxxx";

#define BLYNK_PRINT Serial


int val = 0; 
int pirState;
int x = 0;
WidgetLCD lcd(V1);
WidgetLCD lcd2(V5);
WidgetLCD lcd3(V7);
int ReCnctFlag;  // Reconnection Flag
int ReCnctCount = 0;  
BlynkTimer timer;

BLYNK_WRITE(V0)   
{

  if(param.asInt() == 0){
    pinMode(D0, LOW);
      lcd.print(0, 0, "SWITCH 01 OFF"); 
  }else{
     pinMode(D0, HIGH);
      lcd.print(0, 0, "SWITCH 01 ONN"); 
  }
   
}

BLYNK_WRITE(V2)   
{

  if(param.asInt() == 0){
    pinMode(D1, LOW);
     lcd.print(0, 1, "SWITCH 02 OFF"); 
  }else{
     pinMode(D1, HIGH);
      lcd.print(0, 1, "SWITCH 02 ONN"); 
  }
   
}

BLYNK_WRITE(V3)   
{

  if(param.asInt() == 0){
    pinMode(D5, LOW);
  lcd2.print(0, 0, "SWITCH 03 OFF"); 
  }else{
     pinMode(D5, HIGH);
 lcd2.print(0, 0, "SWITCH 03 ONN"); 
  }
   
}

#define pirPin D4               
int pirValue;   
char replybuffer[255];             
int pinValue;  
SoftwareSerial sim(10, 11);
int _timeout;
String _buffer;

BLYNK_WRITE(V4)   
{
  
  if(param.asInt() == 0){
    pinMode(D3, LOW);
     lcd2.print(0, 1, "SWITCH 04 OFF"); 
  }else{
     pinMode(D3, HIGH);
      lcd2.print(0, 1, "SWITCH 04 ONN"); 
  }
   
}

BLYNK_WRITE(V6)   
{
 pinValue = param.asInt();    
  if(param.asInt() == 0){
    lcd3.clear();
     lcd3.print(0, 1, "HUMAN OFF"); 
  }else{
      lcd3.print(0, 1, "HUMAN ONN"); 
  }
   
}

BLYNK_CONNECTED(){
  Blynk.syncAll();  
}

int calibrationTime = 30;
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int PIRValue = 0;

void setup() { 
  
   Serial.begin(9600);
   
  _buffer.reserve(50);
  Serial.println("System Started...");


  pinMode(D0, OUTPUT);
  pinMode(D1, OUTPUT);
  pinMode(D5, OUTPUT);
  pinMode(D3, OUTPUT);

  pinMode(D0, LOW);
  pinMode(D1, LOW);
  pinMode(D5, LOW);
  pinMode(D3, LOW);
 
  pinMode(pirPin, INPUT_PULLUP);
  
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);
  Serial.print("Connecting to WiFi ..");
  
  Blynk.config(auth, "blynk-cloud.com", 8080);
  Blynk.connect();

  lcd.clear(); 

  timer.setInterval(2500L, reConnect);
  timer.setInterval(2500L, notifiaction);
}

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

void reConnect(){
 
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(1000);
  }

  
}

void notifiaction()
{  
  
  if(pinValue){
    int sensor = digitalRead(pirPin);

    if (sensor == 1) {
        Serial.println("WARNING! Please check your security system");
         Blynk.notify("WARNING! Please check your security system");  
        lcd3.print(0, 0, "MOTION DETACTED.."); 

    }else{
       lcd3.print(0, 0, "MOTION  NOT DETACTED.."); 
    }
  }
 
}```

```Connecting to WiFi ..[68] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on ESP8266

[128] Connecting to blynk-cloud.com:8080
[5128] Connecting to blynk-cloud.com:8080
[5397] Ready (ping: 123ms).
WARNING! Please check your security system```

No, not really, but I’m growing tired of explaining what you should do and you only taking-in part of the message.

All the information you need is in this topic, maybe you should just take the time to re-read it?

Pete.

1 Like

Sir, I cannot understand what you were saying even if i re-read it.Will it work if i use the example sketch?. I am a beginner in coding. Early i used arduino and it worked for 6 months. After that it didnt work. Therefore, I chose nodemcu but it goes offline after 1-2 days and I looked for solution for 3 months and found none.Can you please patiently tell me how it should be done permanently?. Thank you. I appreciate your help :pray:.

Maybe something like this.


BLYNK_CONNECTED() {
  Serial.println("Cconnected");
  Blynk.syncAll();
  ReCnctCount = 0;
}

void initWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);
  Serial.print("Connecting to WiFi ..");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(1000);
  }
  Serial.println(WiFi.localIP());
}


void loop() {
      timer.run();
     if(WiFi.status() != WL_CONNECTED)
     {
       Serial.print("WIFI Reconnecting");
       delay(1000);
       initWiFi();  //  WiFi setup
     }
    else if (Blynk.connected()) 
    {
       Blynk.run();   // If connected run as normal
    } 
   else if (ReCnctFlag == 0) 
   {  
    ReCnctFlag = 1;  // Set reconnection Flag
    Serial.println("Starting reconnection timer in 30 seconds...");
    timer.setTimeout(30000L, []() {  // Lambda Reconnection Timer Function
      ReCnctFlag = 0;  // Reset reconnection Flag
      ReCnctCount++;  // Increment reconnection Counter
      Serial.print("Attempting reconnection #");
      Serial.println(ReCnctCount);
      Blynk.connect();  // Try to reconnect to the server
      });  // END Timer Function
   }  
}

@Toro_Blanco Thank you so much for replying . I was looking for solution for 3 months. Can i apply this to my original sketch?

Yes, with care to make sure you have all of the variables defined and such.

@Toro_Blanco @PeteKnight Thank you so much for solving a big problem for me.

you code complicate the communication stuff. you can pair blynk.begin with wifimanager easily.

I replaced my original coding with the coding you sent. Will it work perfectly without going offline?

Thank you.

#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial

//#define BLYNK_MAX_SENDBYTES 128
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxxx";

char auth[] ="xxxxxxxxxx";

#define BLYNK_PRINT Serial


int val = 0; 
int pirState;
int x = 0;
WidgetLCD lcd(V1);
WidgetLCD lcd2(V5);
WidgetLCD lcd3(V7);
int ReCnctFlag;  // Reconnection Flag
int ReCnctCount = 0;  
BlynkTimer timer;

void initWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);
  Serial.print("Connecting to WiFi ..");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(1000);
  }
  Serial.println(WiFi.localIP());
}

BLYNK_WRITE(V0)   
{

  if(param.asInt() == 0){
    pinMode(D0, LOW);
      lcd.print(0, 0, "SWITCH 01 OFF"); 
  }else{
     pinMode(D0, HIGH);
      lcd.print(0, 0, "SWITCH 01 ONN"); 
  }
   
}

BLYNK_WRITE(V2)   
{

  if(param.asInt() == 0){
    pinMode(D1, LOW);
     lcd.print(0, 1, "SWITCH 02 OFF"); 
  }else{
     pinMode(D1, HIGH);
      lcd.print(0, 1, "SWITCH 02 ONN"); 
  }
   
}

BLYNK_WRITE(V3)   
{

  if(param.asInt() == 0){
    pinMode(D5, LOW);
  lcd2.print(0, 0, "SWITCH 03 OFF"); 
  }else{
     pinMode(D5, HIGH);
 lcd2.print(0, 0, "SWITCH 03 ONN"); 
  }
   
}

#define pirPin D4               
int pirValue;   
char replybuffer[255];             
int pinValue;  
SoftwareSerial sim(10, 11);
int _timeout;
String _buffer;

BLYNK_WRITE(V4)   
{
  
  if(param.asInt() == 0){
    pinMode(D3, LOW);
     lcd2.print(0, 1, "SWITCH 04 OFF"); 
  }else{
     pinMode(D3, HIGH);
      lcd2.print(0, 1, "SWITCH 04 ONN"); 
  }
   
}

BLYNK_WRITE(V6)   
{
 pinValue = param.asInt();    
  if(param.asInt() == 0){
    lcd3.clear();
     lcd3.print(0, 1, "HUMAN OFF"); 
  }else{
      lcd3.print(0, 1, "HUMAN ONN"); 
  }
   
}

BLYNK_CONNECTED(){
  Serial.println("Cconnected");
  Blynk.syncAll();
  ReCnctCount = 0;
}

int calibrationTime = 30;
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int PIRValue = 0;

void setup() { 
  
   Serial.begin(9600);
   
  _buffer.reserve(50);
  Serial.println("System Started...");


  pinMode(D0, OUTPUT);
  pinMode(D1, OUTPUT);
  pinMode(D5, OUTPUT);
  pinMode(D3, OUTPUT);

  pinMode(D0, LOW);
  pinMode(D1, LOW);
  pinMode(D5, LOW);
  pinMode(D3, LOW);
 
  pinMode(pirPin, INPUT_PULLUP);
  
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);
  Serial.print("Connecting to WiFi ..");
  
  Blynk.config(auth, "blynk-cloud.com", 8080);
  Blynk.connect();

  lcd.clear(); 
  
  timer.setInterval(2500L, notifiaction);
}

void loop() {
      timer.run();
     if(WiFi.status() != WL_CONNECTED)
     {
       Serial.print("WIFI Reconnecting");
       delay(1000);
       initWiFi();  //  WiFi setup
     }
    else if (Blynk.connected()) 
    {
       Blynk.run();   // If connected run as normal
    } 
   else if (ReCnctFlag == 0) 
   {  
    ReCnctFlag = 1;  // Set reconnection Flag
    Serial.println("Starting reconnection timer in 30 seconds...");
    timer.setTimeout(30000L, []() {  // Lambda Reconnection Timer Function
      ReCnctFlag = 0;  // Reset reconnection Flag
      ReCnctCount++;  // Increment reconnection Counter
      Serial.print("Attempting reconnection #");
      Serial.println(ReCnctCount);
      Blynk.connect();  // Try to reconnect to the server
      });  // END Timer Function
   }  
}

void notifiaction()
{  
  
  if(pinValue){
    int sensor = digitalRead(pirPin);

    if (sensor == 1) {
        Serial.println("WARNING! Please check your security system");
         Blynk.notify("WARNING! Please check your security system");  
        lcd3.print(0, 0, "MOTION DETACTED.."); 

    }else{
       lcd3.print(0, 0, "MOTION  NOT DETACTED.."); 
    }
  }
 
}```

```⸮⸮System Started...
Connecting to WiFi ..[69] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on ESP8266

[129] Connecting to blynk-cloud.com:8080
[5129] Connecting to blynk-cloud.com:8080
Starting reconnection timer in 30 seconds...
Attempting reconnection #1
[39128] Connecting to blynk-cloud.com:8080
[39385] Ready (ping: 126ms).
Cconnected```