Blynk app keeps disconnecting in home automation system

Hello Guyz,
I have written a code to start my home generator automatically and with blynk on mobile but it keeps disconnecting . code is attached.

[43557] Ready (ping: 36022ms).
AT+CIPSEND=1,40
AT+CIPCLOSE=1

[69321] Login timeout
AT+CIPCLOSE=1

#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
char auth[] = "0*******************************************";
char ssid[] = "PTCL-BB";
char pass[] = "3553C8A8";
#define ESP8266_BAUD 115200
ESP8266 wifi(&Serial);




// Out For Relays //
int GPR    = 6;          
int GSR    = 7;          
int COO    = 8;          


// Digital Read Relays //
int ACCP      = 9;         
int GENP      = 10;  
int UPSP      = 11;  
int UPSBPP    = 12;     

int ACC;         
int GENS;  
int UPS;
int UPSBP;

// Variables //
int TATP     = 4;
int ATP      = 0;          
int COS      = 0;
long int DT  = 60000;



// Mobile Buttons //
int GONM   = 0;
int GOFM   = 0;
int ATS    = 1;
int CONM   = 0;
int COFM   = 0;
int UPSBPM = 0;



void setup()
{
 // Debug console
 Serial.begin(9600);
 delay(10);
 // Set ESP8266 baud rate
 Serial.begin(ESP8266_BAUD);
 delay(10);
 Blynk.begin(auth, wifi, ssid, pass);
 
 
 
 pinMode(GPR, OUTPUT);
 pinMode(GSR, OUTPUT);
 pinMode(COO, OUTPUT);
 
 pinMode(ACCP, INPUT);
 pinMode(GENP, INPUT);
 pinMode(UPSP, INPUT);
 pinMode(UPSBPP, INPUT);
 
 digitalWrite(GPR, HIGH);
 digitalWrite(GSR, HIGH);
 digitalWrite(COO, HIGH);


}




void generatorstart(){

if (ATP <= TATP){
ATP = ATP + 1;
Serial.println("");
Serial.println("Generator Starting!!!");
digitalWrite(GPR,  LOW);
digitalWrite(GSR,  LOW);
delay(3000);
digitalWrite(GSR,  HIGH);
Serial.println("Attempted!!!");
Serial.println("");
delay(15000);

       } else {

Serial.println(ATP);
Serial.println("");
Serial.println("Already attempted 4 times");
Serial.println("Generator Will Not Start Until Reset");
digitalWrite(GPR, HIGH);
digitalWrite(GSR, HIGH);
Serial.println("");
delay(10);
}

}

void generatoroff(){
  
Serial.println("");
Serial.println("Generator Shutting Down!!!"); 
digitalWrite(GPR,   HIGH);

 
}

void changeoveron(){
  Serial.println("COO Over on Routine");
  delay(DT);
  digitalWrite(COO,LOW);
  COS=COS+1;
}

void changeoveroff(){
  Serial.println("COO Over off Routine");
  delay(DT/2);
  digitalWrite(COO,HIGH);
  COS=COS-1;
}

void logics(){



if ( ACC == 0 && (UPSBP == 1 || UPSBPM == 1) && GOFM == 0 && GENS == 0){
Serial.println("");
Serial.println("WAPDA IS OFFLINE!");
Serial.println("UPS IS BYPASSED");
Serial.println("Starting Generator.");
generatorstart();
Serial.println(""); 
}

if ( ACC == 0 && UPS == 0 && GOFM == 0 && GENS == 0){
Serial.println("");
Serial.println("WAPDA IS OFFLINE!");
Serial.println("UPS IS NOT BYPASSED");
Serial.println("UPS IS DISCHARGED");
Serial.println("Starting Generator.");
generatorstart();
Serial.println("");
}

if ( ACC == 0 && (UPSBP == 1 || UPSBPM == 1) && GOFM == 0 && GENS == 1){
Serial.println("");
Serial.println(" Generator Started Sucessfully!!");
Serial.println("Now System Will Reset Number of Attempts");
ATP=0;
Serial.println("");
Serial.println("Now System will run Change Over Routine");
if (COS == 0){
  changeoveron();
}
}

if ( ACC == 0 && UPS == 0 && GOFM == 0 && GENS == 1){
Serial.println("");
Serial.println(" Generator Started Sucessfully!!");
Serial.println("Now System Will Reset Number of Attempts");
ATP=0;
Serial.println("");
Serial.println("Now System will run Change Over Routine");
if (COS == 0){
  changeoveron();
}
}

if ( ACC == 1 && GONM == 0 && GENS == 1){
Serial.println("");
Serial.println("WAPDA IS NOW ONLINE");
Serial.println("GENERATOR WILL NOW STOP");
if (COS == 1){
  changeoveroff();
} 
generatoroff();
}

if ( ACC == 0 && UPS == 1 && UPSBP == 0 && UPSBPM == 0 && GONM == 0 && GENS == 1){
Serial.println("");
Serial.println("UPS IS NOW ONLINE");
Serial.println("GENERATOR WILL NOW STOP");
if (COS == 1){
  changeoveroff();
} 
generatoroff();
}

if ( ACC == 1 && GONM == 0 && GENS == 0){
Serial.println("");
Serial.println("GENERATOR IN NOW SUCESSFULLY STOPPED");  
if (COS == 1){
  changeoveroff();
} 
else 
{
Serial.println("");
Serial.println("CHANGE OVER ROUTINE SUCESSFULL");
} 
  
}

if ( ACC == 0 && UPS == 1 && UPSBP == 0 && UPSBPM == 0 && GONM == 0 && GENS == 0){
Serial.println("");
Serial.println("GENERATOR IN NOW SUCESSFULLY STOPPED"); 
if (COS == 1){
  changeoveroff();
} 
else 
{
Serial.println("");
Serial.println("CHANGE OVER ROUTINE SUCESSFULL");
} 
    
}


}

void overrides(){
  
if ( GONM == 1 && GOFM == 0 && GENS == 0){ 
Serial.println("");
Serial.println("Mobile Over-Ride Activated!!");
Serial.println("Starting Generator.");
Serial.println("Warning Generator will Not Stop Automatically!");
generatorstart();
Serial.println(""); 
} 
  
if ( GONM == 1 && GOFM == 0 && GENS == 1){
Serial.println("");
Serial.println(" Generator Started Sucessfully!!");
Serial.println("Now System Will Reset Number of Attempts");
ATP=0;
Serial.println("");
Serial.println("Now System will run Change Over Routine");
if (COS == 0){
  changeoveron();
}
} 

if ( GOFM == 1 && GENS == 1){
Serial.println("");
Serial.println("MOBILE OVERRIDE");
Serial.println("GENERATOR WILL NOW STOP");
if (COS == 1){
  changeoveroff();
} 
generatoroff();
}

if ( GOFM == 1 && GENS == 0){
Serial.println("");
Serial.println("GENERATOR IN NOW SUCESSFULLY STOPPED"); 
if (COS == 1){
  changeoveroff();
} 
else 
{
Serial.println("");
Serial.println("CHANGE OVER ROUTINE SUCESSFULL");
} 
}

if ( CONM == 1 && COFM == 0){
Serial.println("");
Serial.println("Mobile Over-Ride Activated!!");
Serial.println("INIATING CHANGEOVER ON ROUTINE");
Serial.println("Warning CHANGEOVER will Not TURN OFF Automatically!");
generatorstart();
Serial.println("");   
if (COS == 0){
  changeoveron();
} 
else 
{
Serial.println("");
Serial.println("CHANGE OVER ROUTINE SUCESSFULL");
}
}

if ( CONM == 0 && COFM == 1){
Serial.println("");
Serial.println("Mobile Over-Ride Activated!!");
Serial.println("INIATING CHANGEOVER OFF ROUTINE");
Serial.println("Warning CHANGEOVER will Not TURN ON Automatically!");
generatorstart();
Serial.println("");   
if (COS == 1){
  changeoveroff();
} 
else 
{
Serial.println("");
Serial.println("CHANGE OVER ROUTINE SUCESSFULL");
}


}

}

void readings(){
  
ACC = digitalRead(ACCP); 
GENS = digitalRead(GENP);  
UPS = digitalRead(UPSP); 
UPSBP = digitalRead(UPSBPP);  
  }


void ledsmobile(){

if (ACC == 1){
Blynk.virtualWrite(V7, 255); 
}
else
{
Blynk.virtualWrite(V7, 0);   
}


if (GENS == 1){
Blynk.virtualWrite(V8, 255); 
}
else
{
Blynk.virtualWrite(V8, 0);   
}
  

if (COS == 1){
Blynk.virtualWrite(V9, 255); 
}
else
{
Blynk.virtualWrite(V9, 0);   
} 

if (UPS == 1){
Blynk.virtualWrite(V10, 255); 
}
else
{
Blynk.virtualWrite(V10, 0);   
}
  
 
  }

void loop()
{

Blynk.run();

if ( ATS == 1){
logics(); 
}

overrides();

readings();

ledsmobile();

} 






BLYNK_WRITE(V1) {
 int pinValue = param.asInt();
 if (pinValue == 1) {  
    ATS = 1;  
  } else {
    ATS = 0;
 }
}


BLYNK_WRITE(V2) {
 int pinValue = param.asInt();
 if (pinValue == 1) {  
    UPSBPM = 1;  
  } else {
    UPSBPM = 0;
 }
}


BLYNK_WRITE(V3) {
 int pinValue = param.asInt();
 if (pinValue == 1) {  
    GONM = 1;  
  } else {
    GONM = 0;
 }
}


BLYNK_WRITE(V4) {
 int pinValue = param.asInt();
 if (pinValue == 1) {  
    GOFM = 1;  
  } else {
    GOFM = 0;
 }
}


BLYNK_WRITE(V5) {
 int pinValue = param.asInt();
 if (pinValue == 1) {  
    CONM = 1;  
  } else {
    CONM = 0;
 }
}


BLYNK_WRITE(V6) {
 int pinValue = param.asInt();
 if (pinValue == 1) {  
    COFM = 1;  
  } else {
    COFM = 0;
 }
}

You need to read this:

Pete.

I have changed the void loop code to this
and still getting the same error

void loop()
{

Blynk.run();

timer.setInterval(1000L, overrides);

}

tried this too
overrides is a function

void setup()
{
 // Debug console
 Serial.begin(9600);
 delay(10);
 // Set ESP8266 baud rate
 Serial.begin(ESP8266_BAUD);
 delay(10);
 Blynk.begin(auth, wifi, ssid, pass);
 
 
 
 pinMode(GPR, OUTPUT);
 pinMode(GSR, OUTPUT);
 pinMode(COO, OUTPUT);
 
 pinMode(ACCP, INPUT);
 pinMode(GENP, INPUT);
 pinMode(UPSP, INPUT);
 pinMode(UPSBPP, INPUT);
 
 digitalWrite(GPR, HIGH);
 digitalWrite(GSR, HIGH);
 digitalWrite(COO, HIGH);


timer.setInterval(1000L, overrides);

}

void loop()
{

Blynk.run();
timer.run();


}

The timer initialisation:

timer.setInterval(1000L, overrides);

needs to be in void setup, not void loop.

Your void loop should look like this:

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

I’d suggest you take a little more time to read the document correctly.

Even when you do set-up your timer correctly, if you call a function that takes a long time to execute and then that calls another function, which also takes a long time to execute, you’ll starve the Blynk library of processor time.
The solution to that may be to optimise your code better and/or add Blynk.run() commands into your functions to allow the Blynk libraries to get some processor time.

Pete.

AT+CIPSEND=1,40
AT+CIPCLOSE=1
AT+CIPCLOSE=1
AT+CIPSTART=1,“TCP”,“blynk-cloud.com”,80
AT+CIPSEND=1,37
0e305d6b5b2e42bfb7ce2116dbf99b05[158600] Login timeout

this error now

OK Thank you sir . Thanks for the help

my code but im having same issue

@brownboi please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>
#define ESP8266_BAUD 115200

char auth[] = “Uz6xxCZdK2X11-3AFGKY14AOHiujdmGe”;
char ssid[] = “EsparkTech”; //You can replace the wifi name to your wifi

char pass[] = “IOT1234765”; //Type password of your wifi.

SoftwareSerial EspSerial(8, 9); // RX, TX

ESP8266 wifi(&EspSerial);
SimpleTimer timer;

void setup()
{

Serial.begin(115200);
EspSerial.begin(ESP8266_BAUD);
Blynk.begin(auth, wifi, ssid, pass);

}

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

}```

When I said EDIT I meant that you should edit your post, rather than leaving your unformatted code there and re-posting the code in another post.

As you haven’t done this I’ve deleted your initial post.

The SoftwareSerial library running on the Uno can’t successfully work at a baud rate of 115200.
You need to re-configure your ESP-01 so that it communicates at a baud rate of 9600 and the change you sketch to use the same baud rate. This is done by sending an AT command to the ESP-01
This issue has been discussed many times on the forum in the past, so I’d suggest that you search for information about how to do this.

As your issue is totally unconnected to the original post in this topic I’m closing this topic.
If you require further assistance on this issue I’d suggest that you create a new “need help with my project” topic and provide all of the information that is requested when you create a new topic of this type.

Pete.