Blynk disconnects after many hours or days and stay offline

Dear Blynk community,

I would like to know if someone could help me, I am using the code below with Arduino Mega 2560 + Ethernet Shield W5100, it receives the serial data from a Slave arduino uno over Serial1 port on Mega.

It works just fine, but after a day or many hours it disconnects from Blynk and stay offline, to restore the connection I need to press the reset button on Mega, I suspect that could be something on Serial1 like a limbo?

//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#define W5100_CS  10
#define SDCARD_CS 4
BlynkTimer timer0, timer1, timer2;
int pjn1, sid, ok[10], rssi, i, i1, maxtemp[10], mintemp[10], led[10];
float st, snr, tempmax[10], tempmin[10], batp, batv;

int pjn = 001;                                    //Numero do projeto
char auth[] = "XXX"; //Autenticador

WidgetLED led1(V1); //SENSOR 1 Status LED
WidgetLED led2(V2); //SENSOR 2 Status LED
WidgetLED led3(V3); //SENSOR 3 Status LED
WidgetLED led4(V4); //SENSOR 4 Status LED
WidgetLED led5(V5); //SENSOR 5 Status LED
WidgetLED led6(V6); //SENSOR 6 Status LED
WidgetLED led7(V7); //SENSOR 7 Status LED
WidgetLED led8(V8); //SENSOR 8 Status LED
WidgetLED led9(V9); //SENSOR 9 Status LED
WidgetLED led10(V10); //SENSOR 10 Status LED

#define BLYNK_GREEN     "#23C48E"
#define BLYNK_BLUE      "#04C0F8"
#define BLYNK_YELLOW    "#ED9D00"
#define BLYNK_RED       "#D3435C"
#define BLYNK_DARK_BLUE "#5F7CD8"

BLYNK_CONNECTED()  {Blynk.syncVirtual(V21);     //SENSOR 1 - Get Virtual pin values from server
                    Blynk.syncVirtual(V31);     //SENSOR 1
                    
                    Blynk.syncVirtual(V22);     //SENSOR 2 - Get Virtual pin values from server
                    Blynk.syncVirtual(V32);     //SENSOR 2

                    Blynk.syncVirtual(V23);     //SENSOR 3 - Get Virtual pin values from server
                    Blynk.syncVirtual(V33);     //SENSOR 3 

                    Blynk.syncVirtual(V24);     //SENSOR 4 - Get Virtual pin values from server
                    Blynk.syncVirtual(V34);     //SENSOR 4 

                    Blynk.syncVirtual(V25);     //SENSOR 5 - Get Virtual pin values from server
                    Blynk.syncVirtual(V35);     //SENSOR 5 

                    Blynk.syncVirtual(V26);     //SENSOR 6 - Get Virtual pin values from server
                    Blynk.syncVirtual(V36);     //SENSOR 6 

                    Blynk.syncVirtual(V27);     //SENSOR 7 - Get Virtual pin values from server
                    Blynk.syncVirtual(V37);     //SENSOR 7 

                    Blynk.syncVirtual(V28);     //SENSOR 8 - Get Virtual pin values from server
                    Blynk.syncVirtual(V38);     //SENSOR 8 

                    Blynk.syncVirtual(V29);     //SENSOR 9 - Get Virtual pin values from server
                    Blynk.syncVirtual(V39);     //SENSOR 9 

                    Blynk.syncVirtual(V30);     //SENSOR 10 - Get Virtual pin values from server
                    Blynk.syncVirtual(V40);     //SENSOR 10
                   }
  BLYNK_WRITE(V21){tempmax[1] = param.asDouble();}   // SENSOR 1 Store min and max limit from server, assigning incoming value from pin to a variable
  BLYNK_WRITE(V31){tempmin[1] = param.asDouble();}   // SENSOR 1 assigning incoming value from pin to a variable
  
  BLYNK_WRITE(V22){tempmax[2] = param.asDouble();}   // SENSOR 2 Store min and max limit from server, assigning incoming value from pin to a variable
  BLYNK_WRITE(V32){tempmin[2] = param.asDouble();}   // SENSOR 2 assigning incoming value from pin to a variable
  
  BLYNK_WRITE(V23){tempmax[3] = param.asDouble();}   // SENSOR 3 Store min and max limit from server, assigning incoming value from pin to a variable
  BLYNK_WRITE(V33){tempmin[3] = param.asDouble();}   // SENSOR 3 assigning incoming value from pin to a variable

  BLYNK_WRITE(V24){tempmax[4] = param.asDouble();}   // SENSOR 4 Store min and max limit from server, assigning incoming value from pin to a variable
  BLYNK_WRITE(V34){tempmin[4] = param.asDouble();}   // SENSOR 4 assigning incoming value from pin to a variable

  BLYNK_WRITE(V25){tempmax[5] = param.asDouble();}   // SENSOR 5 Store min and max limit from server, assigning incoming value from pin to a variable
  BLYNK_WRITE(V35){tempmin[5] = param.asDouble();}   // SENSOR 5 assigning incoming value from pin to a variable

  BLYNK_WRITE(V26){tempmax[6] = param.asDouble();}   // SENSOR 6 Store min and max limit from server, assigning incoming value from pin to a variable
  BLYNK_WRITE(V36){tempmin[6] = param.asDouble();}   // SENSOR 6 assigning incoming value from pin to a variable

  BLYNK_WRITE(V27){tempmax[7] = param.asDouble();}   // SENSOR 7 Store min and max limit from server, assigning incoming value from pin to a variable
  BLYNK_WRITE(V37){tempmin[7] = param.asDouble();}   // SENSOR 7 assigning incoming value from pin to a variable

  BLYNK_WRITE(V28){tempmax[8] = param.asDouble();}   // SENSOR 8 Store min and max limit from server, assigning incoming value from pin to a variable
  BLYNK_WRITE(V38){tempmin[8] = param.asDouble();}   // SENSOR 8 assigning incoming value from pin to a variable

  BLYNK_WRITE(V29){tempmax[9] = param.asDouble();}   // SENSOR 9 Store min and max limit from server, assigning incoming value from pin to a variable
  BLYNK_WRITE(V39){tempmin[9] = param.asDouble();}   // SENSOR 9 assigning incoming value from pin to a variable

  BLYNK_WRITE(V30){tempmax[10] = param.asDouble();}   // SENSOR 10 Store min and max limit from server, assigning incoming value from pin to a variable
  BLYNK_WRITE(V40){tempmin[10] = param.asDouble();}   // SENSOR 10 assigning incoming value from pin to a variable
  
void setup()
{
  Serial1.begin(9600);
  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
  Blynk.begin(auth);
  timer0.setInterval(70000L, myTimerEvent0);  //70 seconds between each internet connection check
  timer1.setInterval(180000L, myTimerEvent1); //180 seconds between each sensor status check
  led1.on();
  led1.setColor(BLYNK_RED); 
  led2.on();
  led2.setColor(BLYNK_RED);
  led3.on();
  led3.setColor(BLYNK_RED);
  led4.on();
  led4.setColor(BLYNK_RED);
  led5.on();
  led5.setColor(BLYNK_RED);
  led6.on();
  led6.setColor(BLYNK_RED);
  led7.on();
  led7.setColor(BLYNK_RED);
  led8.on();
  led8.setColor(BLYNK_RED);
  led9.on();
  led9.setColor(BLYNK_RED);
  led10.on();
  led10.setColor(BLYNK_RED);
}

void loop(){
  Blynk.run();
  if (Serial1.available()) {           //If there is serial data, read and store 

    if (Serial1.find("PJN")){
      pjn1 = Serial1.parseInt();
    }
    if (Serial1.find("SID")){
      sid = Serial1.parseInt();
    }
    if (Serial1.find("OK")){
      ok[sid] = Serial1.parseInt();
    }
    if (Serial1.find("ST")){
      st = Serial1.parseFloat();
      st = st/100;
    }
    if (Serial1.find("RSSI")){
      rssi = Serial1.parseInt();
    }
    if (Serial1.find("SNR")){
      snr = Serial1.parseFloat();
      snr = snr/100;
    }
    if (Serial1.find("BATP")){
      batp = Serial1.parseFloat();
    }
    if (Serial1.find("BATV")){
      batv = Serial1.parseFloat();
    }
    else {
      char C = Serial.read();
    }
  i1 = 1;
  }
  Serial1.flush();
    if ((pjn1 == pjn) && (i1 == 1)){
      //Sensor 1
      if ((sid == 1) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V11, st);  } 
      if ((sid == 1) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V41, rssi);}
      if ((sid == 1) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V51, snr); }
      if ((sid == 1) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V61, batp);}
      if ((sid == 1) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V71, batv);}
      if ((sid == 1) && (ok[sid] == 1) && (led[sid] == 0)){
      led1.setColor(BLYNK_GREEN);
      Blynk.email("Sensor 1 ONLINE", "Sensor 1 OK");
      Blynk.notify("Sensor 1 ONLINE");
      led[1] = 1;
      }
                                               
      //Sensor 2
      
      if ((sid == 2) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V12, st);  } 
      if ((sid == 2) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V42, rssi);}
      if ((sid == 2) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V52, snr); }
      if ((sid == 2) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V62, batp);}
      if ((sid == 2) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V72, batv);}
      if ((sid == 2) && (ok[sid] == 1) && (led[sid] == 0)){
      led2.setColor(BLYNK_GREEN);
      Blynk.email("Sensor 2 ONLINE", "Sensor 2 OK");
      Blynk.notify("Sensor 2 ONLINE");
      led[2] = 1;  
      }
      
      //Sensor 3
      
      if ((sid == 3) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V13, st);  } 
      if ((sid == 3) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V43, rssi);}
      if ((sid == 3) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V53, snr); }
      if ((sid == 3) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V63, batp);}
      if ((sid == 3) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V73, batv);}
      if ((sid == 3) && (ok[sid] == 1) && (led[sid] == 0)){
      led3.setColor(BLYNK_GREEN);
      Blynk.email("Sensor 3 ONLINE", "Sensor 3 OK");
      Blynk.notify("Sensor 3 ONLINE");
      led[3] = 1;  
      }

      //Sensor 4
      
      if ((sid == 4) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V14, st);  } 
      if ((sid == 4) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V44, rssi);}
      if ((sid == 4) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V54, snr); }
      if ((sid == 4) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V64, batp);}
      if ((sid == 4) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V74, batv);}
      if ((sid == 4) && (ok[sid] == 1) && (led[sid] == 0)){
      led4.setColor(BLYNK_GREEN);
      Blynk.email("Sensor 4 ONLINE", "Sensor 4 OK");
      Blynk.notify("Sensor 4 ONLINE");
      led[4] = 1;  
      }


      //Sensor 5
      
      if ((sid == 5) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V15, st);  } 
      if ((sid == 5) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V45, rssi);}
      if ((sid == 5) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V55, snr); }
      if ((sid == 5) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V65, batp);}
      if ((sid == 5) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V75, batv);}
      if ((sid == 5) && (ok[sid] == 1) && (led[sid] == 0)){
      led5.setColor(BLYNK_GREEN);
      Blynk.email("Sensor 5 ONLINE", "Sensor 5 OK");
      Blynk.notify("Sensor 5 ONLINE");
      led[5] = 1;  
      }


      //Sensor 6
      
      if ((sid == 6) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V16, st);  } 
      if ((sid == 6) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V46, rssi);}
      if ((sid == 6) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V56, snr); }
      if ((sid == 6) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V66, batp);}
      if ((sid == 6) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V76, batv);}
      if ((sid == 6) && (ok[sid] == 1) && (led[sid] == 0)){
      led6.setColor(BLYNK_GREEN);
      Blynk.email("Sensor 6 ONLINE", "Sensor 6 OK");
      Blynk.notify("Sensor 6 ONLINE");
      led[6] = 1;  
      }


      //Sensor 7
      
      if ((sid == 7) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V17, st);  } 
      if ((sid == 7) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V47, rssi);}
      if ((sid == 7) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V57, snr); }
      if ((sid == 7) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V67, batp);}
      if ((sid == 7) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V77, batv);}
      if ((sid == 7) && (ok[sid] == 1) && (led[sid] == 0)){
      led7.setColor(BLYNK_GREEN);
      Blynk.email("Sensor 7 ONLINE", "Sensor 7 OK");
      Blynk.notify("Sensor 7 ONLINE");
      led[7] = 1;  
      }


      //Sensor 8
      
      if ((sid == 8) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V18, st);  } 
      if ((sid == 8) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V48, rssi);}
      if ((sid == 8) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V58, snr); }
      if ((sid == 8) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V68, batp);}
      if ((sid == 8) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V78, batv);}
      if ((sid == 8) && (ok[sid] == 1) && (led[sid] == 0)){
      led8.setColor(BLYNK_GREEN);
      Blynk.email("Sensor 8 ONLINE", "Sensor 8 OK");
      Blynk.notify("Sensor 8 ONLINE");
      led[8] = 1;  
      }


      //Sensor 9
      
      if ((sid == 9) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V19, st);  } 
      if ((sid == 9) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V49, rssi);}
      if ((sid == 9) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V59, snr); }
      if ((sid == 9) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V69, batp);}
      if ((sid == 9) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V79, batv);}
      if ((sid == 9) && (ok[sid] == 1) && (led[sid] == 0)){
      led9.setColor(BLYNK_GREEN);
      Blynk.email("Sensor 9 ONLINE", "Sensor 9 OK");
      Blynk.notify("Sensor 9 ONLINE");
      led[9] = 1;  
      }


      //Sensor 10
      
      if ((sid == 10) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V20, st);  } 
      if ((sid == 10) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V50, rssi);}
      if ((sid == 10) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V60, snr); }
      if ((sid == 10) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V70, batp);}
      if ((sid == 10) && (ok[sid] == 1) && (batp >  0)){Blynk.virtualWrite(V80, batv);}
      if ((sid == 10) && (ok[sid] == 1) && (led[sid] == 0)){
      led10.setColor(BLYNK_GREEN);
      Blynk.email("Sensor 10 ONLINE", "Sensor 10 OK");
      Blynk.notify("Sensor 10 ONLINE");
      led[10] = 1;  
      }
       
      
    

    if ((sid == 1) && (ok[sid] == 1) && (st > tempmax[sid]) && (maxtemp[sid] < 1)){Blynk.email("Temperatura 1 - Alta", "O valor de temperatura máxima definida pelo aplicativo foi atingido!");
                                                                              Blynk.notify("Temperatura 1 Alta");
                                                                              maxtemp[sid] = 1;  }                                                                         
    if ((sid == 1) && (ok[sid] == 1) && (st < tempmin[sid]) && (mintemp[sid] < 1)){Blynk.email("Temperatura 1 - Baixa", "O valor de temperatura mĂ­nima definida pelo aplicativo foi atingido!");
                                                                              Blynk.notify("Temperatura 1 Baixa");
                                                                              mintemp[sid] = 1;  }
    if ((sid == 2) && (ok[sid] == 1) && (st > tempmax[sid]) && (maxtemp[sid] < 1)){  Blynk.email("Temperatura 2 - Alta", "O valor de temperatura máxima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 2 Alta");
                                                                              maxtemp[sid] = 1;   }                                                                         
    if ((sid == 2) && (ok[sid] == 1) && (st < tempmin[sid]) && (mintemp[sid] < 1)){  Blynk.email("Temperatura 2 - Baixa", "O valor de temperatura mĂ­nima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 2 Baixa"); 
                                                                              mintemp[sid] = 1;   }
    if ((sid == 3) && (ok[sid] == 1) && (st > tempmax[sid]) && (maxtemp[sid] < 1)){  Blynk.email("Temperatura 3 - Alta", "O valor de temperatura máxima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 3 Alta");
                                                                              maxtemp[sid] = 1;   }                                                                         
    if ((sid == 3) && (ok[sid] == 1) && (st < tempmin[sid]) && (mintemp[sid] < 1)){  Blynk.email("Temperatura 3 - Baixa", "O valor de temperatura mĂ­nima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 3 Baixa");
                                                                              mintemp[sid] = 1;   }
    if ((sid == 4) && (ok[sid] == 1) && (st > tempmax[sid]) && (maxtemp[sid] < 1)){  Blynk.email("Temperatura 4 - Alta", "O valor de temperatura máxima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 4 Alta");
                                                                              maxtemp[sid] = 1;   }                                                                         
    if ((sid == 4) && (ok[sid] == 1) && (st < tempmin[sid]) && (mintemp[sid] < 1)){  Blynk.email("Temperatura 4 - Baixa", "O valor de temperatura mĂ­nima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 4 Baixa");
                                                                              mintemp[sid] = 1;   }
    if ((sid == 5) && (ok[sid] == 1) && (st > tempmax[sid]) && (maxtemp[sid] < 1)){  Blynk.email("Temperatura 5 - Alta", "O valor de temperatura máxima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 5 Alta");
                                                                              maxtemp[sid] = 1;   }                                                                         
    if ((sid == 5) && (ok[sid] == 1) && (st < tempmin[sid]) && (mintemp[sid] < 1)){  Blynk.email("Temperatura 5 - Baixa", "O valor de temperatura mĂ­nima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 5 Baixa");
                                                                              mintemp[sid] = 1;   }
    if ((sid == 6) && (ok[sid] == 1) && (st > tempmax[sid]) && (maxtemp[sid] < 1)){  Blynk.email("Temperatura 6 - Alta", "O valor de temperatura máxima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 6 Alta");
                                                                              maxtemp[sid] = 1;   }                                                                         
    if ((sid == 6) && (ok[sid] == 1) && (st < tempmin[sid]) && (mintemp[sid] < 1)){  Blynk.email("Temperatura 6 - Baixa", "O valor de temperatura mĂ­nima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 6 Baixa");
                                                                              mintemp[sid] = 1;   }
    if ((sid == 7) && (ok[sid] == 1) && (st > tempmax[sid]) && (maxtemp[sid] < 1)){  Blynk.email("Temperatura 7 - Alta", "O valor de temperatura máxima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 7 Alta");
                                                                              maxtemp[sid] = 1;   }                                                                         
    if ((sid == 7) && (ok[sid] == 1) && (st < tempmin[sid]) && (mintemp[sid] < 1)){  Blynk.email("Temperatura 7 - Baixa", "O valor de temperatura mĂ­nima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 7 Baixa");
                                                                              mintemp[sid] = 1;   }
    if ((sid == 8) && (ok[sid] == 1) && (st > tempmax[sid]) && (maxtemp[sid] < 1)){  Blynk.email("Temperatura 8 - Alta", "O valor de temperatura máxima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 8 Alta");
                                                                              maxtemp[sid] = 1;   }                                                                         
    if ((sid == 8) && (ok[sid] == 1) && (st < tempmin[sid]) && (mintemp[sid] < 1)){  Blynk.email("Temperatura 8 - Baixa", "O valor de temperatura mĂ­nima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 8 Baixa");
                                                                              mintemp[sid] = 1;   }
    if ((sid == 9) && (ok[sid] == 1) && (st > tempmax[sid]) && (maxtemp[sid] < 1)){  Blynk.email("Temperatura 9 - Alta", "O valor de temperatura máxima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 9 Alta");
                                                                              maxtemp[sid] = 1;   }                                                                         
    if ((sid == 9) && (ok[sid] == 1) && (st < tempmin[sid]) && (mintemp[sid] < 1)){  Blynk.email("Temperatura 9 - Baixa", "O valor de temperatura mĂ­nima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 9 Baixa");
                                                                              mintemp[sid] = 1;   }
    if ((sid == 10) && (ok[sid] == 1) && (st > tempmax[sid]) && (maxtemp[sid] < 1)){ Blynk.email("Temperatura 10 - Alta", "O valor de temperatura máxima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 10 Alta");
                                                                              maxtemp[sid] = 1;   }                                                                         
    if ((sid == 10) && (ok[sid] == 1) && (st < tempmin[sid]) && (mintemp[sid] < 1)){ Blynk.email("Temperatura 10 - Baixa", "O valor de temperatura mĂ­nima definida pelo aplicativo foi atingido!");
                                                                                Blynk.notify("Temperatura 10 Baixa");
                                                                              mintemp[sid] = 1;   }
                                                                              
                                                                                                                                                          
    if ((sid == 1) && (st < tempmax[sid]))                                    {  maxtemp[sid] = 0;}
    if ((sid == 1) && (st > tempmin[sid]))                                    {  mintemp[sid] = 0;}
    if ((sid == 2) && (st < tempmax[sid]))                                    {  maxtemp[sid] = 0;}
    if ((sid == 2) && (st > tempmin[sid]))                                    {  mintemp[sid] = 0;}
    if ((sid == 3) && (st < tempmax[sid]))                                    {  maxtemp[sid] = 0;}
    if ((sid == 3) && (st > tempmin[sid]))                                    {  mintemp[sid] = 0;}
    if ((sid == 4) && (st < tempmax[sid]))                                    {  maxtemp[sid] = 0;}
    if ((sid == 4) && (st > tempmin[sid]))                                    {  mintemp[sid] = 0;}
    if ((sid == 5) && (st < tempmax[sid]))                                    {  maxtemp[sid] = 0;}
    if ((sid == 5) && (st > tempmin[sid]))                                    {  mintemp[sid] = 0;}
    if ((sid == 6) && (st < tempmax[sid]))                                    {  maxtemp[sid] = 0;}
    if ((sid == 6) && (st > tempmin[sid]))                                    {  mintemp[sid] = 0;}
    if ((sid == 7) && (st < tempmax[sid]))                                    {  maxtemp[sid] = 0;}
    if ((sid == 7) && (st > tempmin[sid]))                                    {  mintemp[sid] = 0;}
    if ((sid == 8) && (st < tempmax[sid]))                                    {  maxtemp[sid] = 0;}
    if ((sid == 8) && (st > tempmin[sid]))                                    {  mintemp[sid] = 0;}
    if ((sid == 9) && (st < tempmax[sid]))                                    {  maxtemp[sid] = 0;}
    if ((sid == 9) && (st > tempmin[sid]))                                    {  mintemp[sid] = 0;}
    if ((sid == 10) && (st < tempmax[sid]))                                   {  maxtemp[sid] = 0;}
    if ((sid == 10) && (st > tempmin[sid]))                                   {  mintemp[sid] = 0;}
    i1 = 0;
    }
            
  //} //End of serial read event
  timer0.run(); // Initiates BlynkTimer
  timer1.run(); // Initiates BlynkTimer

} //End of main LOOP event

void myTimerEvent0(){ //Loop to check internet connection
  if ((Blynk.connected() == true) && (i == 0)) {        //Check if Blynk is connected to internet and send message                                                                          
    Blynk.email("Blynk ONLINE!", "A conexĂŁo com a internet foi estabelecida com sucesso!");
    Blynk.notify("Blynk ONLINE");
    digitalWrite(7, HIGH);
    i = 1;
   }
   if (Blynk.connected() == false) {
    i = 0;
   }   
}

void myTimerEvent1(){ //Loop to check if sensors are alive

    if ((ok[1] == 0) && (led[1] == 1)){
      led1.setColor(BLYNK_RED);
      Blynk.email("Sensor 1 OFFLINE", "Sensor 1 Sem resposta!");
      Blynk.notify("Sensor 1 OFFLINE");
      led[1] = 0;
    }
    if ((ok[2] == 0) && (led[2] == 1)){
      led2.setColor(BLYNK_RED);
      Blynk.email("Sensor 2 OFFLINE", "Sensor 2 Sem resposta!");
      Blynk.notify("Sensor 2 OFFLINE");
      led[2] = 0;
    }
    if ((ok[3] == 0) && (led[3] == 1)){
      led3.setColor(BLYNK_RED);
      Blynk.email("Sensor 3 OFFLINE", "Sensor 3 Sem resposta!");
      Blynk.notify("Sensor 3 OFFLINE");
      led[3] = 0;
    }
    if ((ok[4] == 0) && (led[4] == 1)){
      led4.setColor(BLYNK_RED);
      Blynk.email("Sensor 4 OFFLINE", "Sensor 4 Sem resposta!");
      Blynk.notify("Sensor 4 OFFLINE");
      led[4] = 0;
    }
    if ((ok[5] == 0) && (led[5] == 1)){
      led5.setColor(BLYNK_RED);
      Blynk.email("Sensor 5 OFFLINE", "Sensor 5 Sem resposta!");
      Blynk.notify("Sensor 5 OFFLINE");
      led[5] = 0;
    }
    if ((ok[6] == 0) && (led[6] == 1)){
      led6.setColor(BLYNK_RED);
      Blynk.email("Sensor 6 OFFLINE", "Sensor 6 Sem resposta!");
      Blynk.notify("Sensor 6 OFFLINE");
      led[6] = 0;
    }
    if ((ok[7] == 0) && (led[7] == 1)){
      led7.setColor(BLYNK_RED);
      Blynk.email("Sensor 7 OFFLINE", "Sensor 7 Sem resposta!");
      Blynk.notify("Sensor 7 OFFLINE");
      led[7] = 0;
    }
    if ((ok[8] == 0) && (led[8] == 1)){
      led8.setColor(BLYNK_RED);
      Blynk.email("Sensor 8 OFFLINE", "Sensor 8 Sem resposta!");
      Blynk.notify("Sensor 8 OFFLINE");
      led[8] = 0;
    }
    if ((ok[9] == 0) && (led[9] == 1)){
      led9.setColor(BLYNK_RED);
      Blynk.email("Sensor 9 OFFLINE", "Sensor 9 Sem resposta!");
      Blynk.notify("Sensor 9 OFFLINE");
      led[9] = 0;
    }
    if ((ok[10] == 0) && (led[10] == 1)){
      led10.setColor(BLYNK_RED);
      Blynk.email("Sensor 10 OFFLINE", "Sensor 10 Sem resposta!");
      Blynk.notify("Sensor 10 OFFLINE");
      led[10] = 0;
    }

  ok[1] = 0;
  ok[2] = 0;
  ok[3] = 0;
  ok[4] = 0;
  ok[5] = 0;
  ok[6] = 0;
  ok[7] = 0;
  ok[8] = 0;
  ok[9] = 0;
  ok[10] = 0;
}



Because of direct dependencies with other devices, it is impossible (at least for me) to point to one or other issue. But as Your loop() is quite congested with many calls to Blynk routines one of the reasons might be a disconnect because of flooding the server.

Hello @marvin7 I forgot to tell that I send a message over serial each 1 minute and only for sensor id 1 so only v11, v41, v51, v61 and v71 are updated each 1 minute. All the rest are not used now…

But now you made me think that maybe I need and interval between v11, v41, v51, v61 and v71.

They are updated each 1 min but all at once which may be flooding.

Not even going to touch the congested void loop :stuck_out_tongue: But I would recommend something like EasyTransfer instead of basic serial… works in background.

As for reconnection, Ethernet shields are notoriously unstable, and Blynk connection management is mostly geared for standalone ESP use, but still possible to initiate a reconnection or even reboot with Arduino WDT when connection is lost.

I told you once (loong time ago): Mine is special - it was (and probably still is) rock stable, when i was using it. NOW FOR SALE!!!
…Just kidding :stuck_out_tongue:

As a last resort - Yes, it is usable, and of course - working. Still I think it is not optimal solution…

1 Like

Hello @marvin7 and @Gunner

I have changed my code and put in loop() only blynk.begin, blynk.timers and serial read.

The code is running with ethernet shield w5100 already for almost 24 hours without any surprises. There is one Blynk timer for each variable which is being sent to Blynk server, and I put 1 second interval between each one.

//#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

BlynkTimer timer0, timer1, timer2, timer3, timer4, timer5, timer6;
int pjn1, sid, ok[10], rssi, i, maxtemp[10], mintemp[10], led[10], st1, rssi1, snr1, batp1, batv1;
float st, snr, tempmax[10], tempmin[10], batp, batv;

int pjn = 001;                                    //Numero do projeto
char auth[] = "XXX";

#define W5100_CS  10
#define SDCARD_CS 4

BlynkTimer timer;

WidgetLED led1(V1); //SENSOR 1 Status LED

#define BLYNK_GREEN     "#23C48E"
#define BLYNK_BLUE      "#04C0F8"
#define BLYNK_YELLOW    "#ED9D00"
#define BLYNK_RED       "#D3435C"
#define BLYNK_DARK_BLUE "#5F7CD8"

BLYNK_CONNECTED()  {
  Blynk.syncVirtual(V21);     //SENSOR 1 - Get Virtual pin values from server
  Blynk.syncVirtual(V31);     //SENSOR 1
}

BLYNK_WRITE(V21) {
  tempmax[1] = param.asDouble(); // SENSOR 1 Store min and max limit from server, assigning incoming value from pin to a variable
}
BLYNK_WRITE(V31) {
  tempmin[1] = param.asDouble(); // SENSOR 1 assigning incoming value from pin to a variable
}


void myTimerEvent0()
{
  if (pjn1 == pjn) {
    if ((sid == 1) && (ok[sid] == 1) && (st1 == 1)) {
      Blynk.virtualWrite(V11, st);
    }
    if ((sid == 1) && (ok[sid] == 1) && (led[sid] == 0)) {
      led1.setColor(BLYNK_GREEN);
      Blynk.email("Sensor 1 ONLINE", "Sensor 1 OK");
      Blynk.notify("Sensor 1 ONLINE");
      led[1] = 1;
    }
  }
  st1 = 0;
}

void myTimerEvent1()
{
  if (pjn1 == pjn) {
    if ((sid == 1) && (ok[sid] == 1) && (rssi1 = 1)) {
      Blynk.virtualWrite(V41, rssi);
    }
  }
  rssi1 = 0;
}

void myTimerEvent2()
{
  if (pjn1 == pjn) {
    if ((sid == 1) && (ok[sid] == 1) && (snr1 == 1)) {
      Blynk.virtualWrite(V51, snr);
    }
  }
  snr1 = 0;
}

void myTimerEvent3()
{
  if (pjn1 == pjn) {
    if ((sid == 1) && (ok[sid] == 1) && (batp1 == 1)) {
      Blynk.virtualWrite(V61, batp);
    }
  }
  batp1 = 0;
}

void myTimerEvent4()
{
  if (pjn1 == pjn) {
    if ((sid == 1) && (ok[sid] == 1) && (batv1 == 1)) {
      Blynk.virtualWrite(V71, batv);
    }
  }
  batv1 = 0;
}

void myTimerEvent5() { //Loop to check if sensors are alive

  if ((ok[1] == 0) && (led[1] == 1)) {
    led1.setColor(BLYNK_RED);
    Blynk.email("Sensor 1 OFFLINE", "Sensor 1 Sem resposta!");
    Blynk.notify("Sensor 1 OFFLINE");
    led[1] = 0;
  }
  ok[1] = 0;
}

void myTimerEvent6() { //Loop to check internet connection
  if ((Blynk.connected() == true) && (i == 0)) {        //Check if Blynk is connected to internet and send message
    Blynk.email("ONLINE!", "A conexĂŁo com a internet foi estabelecida com sucesso!");
    Blynk.notify("ONLINE");
    digitalWrite(7, HIGH);
    i = 1;
  }
  if (Blynk.connected() == false) {
    i = 0;
  }
}

void setup()
{
  Serial1.begin(9600);
  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
  led1.on();
  led1.setColor(BLYNK_RED);
  Blynk.begin(auth);

  timer0.setInterval(1000L, myTimerEvent0); // 1 Second interval
  timer1.setInterval(2000L, myTimerEvent1); // 2 Second interval
  timer2.setInterval(3000L, myTimerEvent2); // 3 Second interval
  timer3.setInterval(4000L, myTimerEvent3); // 4 Second interval
  timer4.setInterval(5000L, myTimerEvent4); // 4 Second interval
  timer5.setInterval(180700L, myTimerEvent5); //180.7 seconds between each sensor status check
  timer6.setInterval(70500L, myTimerEvent6);  //70.5 seconds between each internet connection check
}

void loop()
{
  Blynk.run();
  timer0.run(); // Temperature
  timer1.run(); // RSSI
  timer2.run(); // SNR
  timer3.run(); // BATP
  timer4.run(); // BATV
  timer5.run(); // Sensors Check
  timer6.run(); // Internet connection Check
  if (Serial1.available()) {           //If there is serial data, read and store

    if (Serial1.find("PJN")) {
      pjn1 = Serial1.parseInt();
    }
    if (Serial1.find("SID")) {
      sid = Serial1.parseInt();
    }
    if (Serial1.find("OK")) {
      ok[sid] = Serial1.parseInt();
    }
    if (Serial1.find("ST")) {
      st = Serial1.parseFloat();
      st = st / 100;
      st1 = 1;
    }
    if (Serial1.find("RSSI")) {
      rssi = Serial1.parseInt();
      rssi1 = 1;
    }
    if (Serial1.find("SNR")) {
      snr = Serial1.parseFloat();
      snr = snr / 100;
      snr1 = 1;
    }
    if (Serial1.find("BATP")) {
      batp = Serial1.parseFloat();
      batp1 = 1;
    }
    if (Serial1.find("BATV")) {
      batv = Serial1.parseFloat();
      batv1 = 1;
    }
    else {
      char C = Serial.read();
    }

  }

}



Much better looking now. :slight_smile:
One important note however: I’m sure you are aware of this, but be careful when using Serial.find() and Serial.parseInt(), as they are blocking functions. Some read error, and you (well, your hardware) will wait until they timeouts… And Blynk doesn’t like much waiting :wink:

Hello @marvin7 yes that’s going to be my next change if it still unstable, but so far so good! :slight_smile:

Hello @marvin7 and @Gunner long time since the last post on this topic but I have been struggling with this and still have the same issue. It is still very unstable regarding connection to Blynk cloud.

I have implemented the EasyTransfer instead of Serial.find or Parse functions to avoid delays and reduced the program code, but, still sometimes the devices status on Blynk app goes to offline and stays like that for ever. if I go to the ESP board and press reset button, status is online again. I have also tried on two more ESP32 boards and power supplies to check if there could be a hardware problem, but, still the same…

Could you please help?

I am now using the ESP32 Dev Module board with the following code:
(PS. there are few minutes between each ETin.receiveData() because I am working with battery powered sensors with radio module, so they measure temperature, humidity and send battery level each 15 minutes). The idea here is to have up to 18 sensors for each ESP32 which will act as a gateway.

//#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
#include <EasyTransfer.h>
#include <HardwareSerial.h>
#define BLYNK_GREEN     "#23C48E"
#define BLYNK_BLUE      "#04C0F8"
#define BLYNK_YELLOW    "#ED9D00"
#define BLYNK_RED       "#D3435C"
#define BLYNK_DARK_BLUE "#5F7CD8"
WidgetRTC rtc;
WidgetLED led1(V0);    //SENSOR 1  Status LED
WidgetLED led2(V1);    //SENSOR 2  Status LED
WidgetLED led3(V2);    //SENSOR 3  Status LED
WidgetLED led4(V3);    //SENSOR 4  Status LED
WidgetLED led5(V4);    //SENSOR 5  Status LED
WidgetLED led6(V5);    //SENSOR 6  Status LED
WidgetLED led7(V6);    //SENSOR 7  Status LED
WidgetLED led8(V7);    //SENSOR 8  Status LED
WidgetLED led9(V8);    //SENSOR 9  Status LED
WidgetLED led10(V9);   //SENSOR 10 Status LED
WidgetLED led11(V10);  //SENSOR 11 Status LED
WidgetLED led12(V11);  //SENSOR 12 Status LED
WidgetLED led13(V12);  //SENSOR 13 Status LED
WidgetLED led14(V13);  //SENSOR 14 Status LED
WidgetLED led15(V14);  //SENSOR 15 Status LED
WidgetLED led16(V15);  //SENSOR 16 Status LED
WidgetLED led17(V16);  //SENSOR 17 Status LED
WidgetLED led18(V17);  //SENSOR 18 Status LED
WiFiClient client;

BlynkTimer Timer_500ms, Timer_30min;
EasyTransfer ETin, ETout;

float st[18], sh[18], sp[18], st_buffer, sh_buffer, sp_buffer;
unsigned int num_of_sensors = 1, pjn_buffer, sid_buffer, info_buffer, counter_500ms, sensor_status[18], sensor_alive[18];
byte data_received, data_ready_for_blynk[18];

HardwareSerial MySerial(1);

struct RECEIVE_DATA_STRUCTURE {
  uint16_t pjn_et;   //0 <-> 65535
  uint16_t sid_et;   //0 <-> 65535
  int16_t st_et;     //-55.00oC <-> +125.00oC
  uint16_t sh_et;    //0.00% <-> 100.00%
  uint16_t sp_et;    //0.00% <-> 100.00%
  uint16_t info_et;   //0 <-> 65535;
};
struct SEND_DATA_STRUCTURE {
  uint16_t pjn_et;   //0 <-> 65535
  uint16_t sid_et;   //0 <-> 65535
  int16_t st_et;     //-55.00oC <-> +125.00oC
  uint16_t sh_et;    //0.00% <-> 100.00%
  uint16_t sp_et;    //0.00% <-> 100.00%
  uint16_t info_et;   //0 <-> 65535;
};

RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;

char auth[] = "XXX";
char ssid[] = "XXX";
char pass[] = "XXX";

uint16_t pjn_num = 1;
uint16_t central_num = 1;
uint16_t first_sensor_num = 1;
uint16_t last_sensor_num = 13;

/*
   info = 100   => Normal operation, central sends sensor values to Blynk
   info = 1   => Sensor is alive and asking for programming
   info = 2   => Central sends pg_pjn and sid_pjn to sensor
   info = 3   => Sensor replies with succesfull programming sequence
*/

BLYNK_CONNECTED()  {
  Blynk.syncAll();
}

void setup() {
  Serial.begin(9600);
  MySerial.begin(9600, SERIAL_8N1, 22, 23); //RX e TX
  ETin.begin(details(rxdata), &MySerial);
  ETout.begin(details(txdata), &MySerial);
  Blynk.begin(auth, ssid, pass);
  rtc.begin();
  Timer_500ms.setInterval(300L, Periodic_500_ms);
  Timer_30min.setInterval(1800000L, Periodic_30_min);
}

void loop() {
  Blynk.run();
  Timer_500ms.run();
  Timer_30min.run();
  if (ETin.receiveData()) {
    pjn_buffer = rxdata.pjn_et;
    sid_buffer = rxdata.sid_et;
    st_buffer = rxdata.st_et;
    sh_buffer = rxdata.sh_et;
    sp_buffer = rxdata.sp_et;
    info_buffer = rxdata.info_et;
    data_received = 1;
  }
  if ((data_received == 1) && (pjn_buffer == pjn_num) && (sid_buffer >= first_sensor_num) && (sid_buffer <= last_sensor_num) && (info_buffer == 100)) {
    //So sid_buffer is always between 1 and 13 even when sid is higher than 13 (Central 2, 3, ....).
    if (sid_buffer > 13) {
      sid_buffer = (sid_buffer - first_sensor_num) + 1;
    }
    if (sid_buffer > num_of_sensors) {
      num_of_sensors = sid_buffer;
    }
    st[sid_buffer] = st_buffer / 100;
    sh[sid_buffer] = sh_buffer / 100;
    sp[sid_buffer] = sp_buffer / 100;
    data_ready_for_blynk[sid_buffer] = 1;
    data_received = 0;
  }
}

void Periodic_500_ms() {
  if (data_ready_for_blynk[counter_500ms] == 1) {
    Blynk.virtualWrite(127 + counter_500ms, st[counter_500ms]);  // SENDS TEMPERATURE VALUE TO BLYNK
    Blynk.virtualWrite(145 + counter_500ms, sh[counter_500ms]);  // SENDS HUMIDITY VALUE TO BLYNK
    Blynk.virtualWrite(163 + counter_500ms, sp[counter_500ms]);  // SENDS BATTERY VALUE TO BLYNK
    sensor_alive[counter_500ms] = 1;
    if (sensor_status[counter_500ms] == 0) {
      if (counter_500ms == 1) {
        led1.on();
        led1.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 2) {
        led2.on();
        led2.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 3) {
        led3.on();
        led3.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 4) {
        led4.on();
        led4.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 5) {
        led5.on();
        led5.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 6) {
        led6.on();
        led6.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 7) {
        led7.on();
        led7.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 8) {
        led8.on();
        led8.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 9) {
        led9.on();
        led9.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 10) {
        led10.on();
        led10.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 11) {
        led11.on();
        led11.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 12) {
        led12.on();
        led12.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 13) {
        led13.on();
        led13.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 14) {
        led14.on();
        led14.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 15) {
        led15.on();
        led15.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 16) {
        led16.on();
        led16.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 17) {
        led17.on();
        led17.setColor(BLYNK_GREEN);
      }
      else if (counter_500ms == 18) {
        led18.on();
        led18.setColor(BLYNK_GREEN);
      }
      sensor_status[counter_500ms] = 1;
    }
    data_ready_for_blynk[counter_500ms] = 0;
  }
  counter_500ms++;
  if (counter_500ms > num_of_sensors) {
    counter_500ms = 0;
  }
}

void Periodic_30_min() {
  for (int i = 0; i <= num_of_sensors; i++) {
    if ((sensor_alive[i] == 0) && (sensor_status[i] == 1)) {
      sensor_status[i] = 0;
      if (i == 1) {
        led1.setColor(BLYNK_RED);
      }
      else if (i == 2) {
        led2.setColor(BLYNK_RED);
      }
      else if (i == 3) {
        led3.setColor(BLYNK_RED);
      }
      else if (i == 4) {
        led4.setColor(BLYNK_RED);
      }
      else if (i == 5) {
        led5.setColor(BLYNK_RED);
      }
      else if (i == 6) {
        led6.setColor(BLYNK_RED);
      }
      else if (i == 7) {
        led7.setColor(BLYNK_RED);
      }
      else if (i == 8) {
        led8.setColor(BLYNK_RED);
      }
      else if (i == 9) {
        led9.setColor(BLYNK_RED);
      }
      else if (i == 10) {
        led10.setColor(BLYNK_RED);
      }
      else if (i == 11) {
        led11.setColor(BLYNK_RED);
      }
      else if (i == 12) {
        led12.setColor(BLYNK_RED);
      }
      else if (i == 13) {
        led13.setColor(BLYNK_RED);
      }
      else if (i == 14) {
        led14.setColor(BLYNK_RED);
      }
      else if (i == 15) {
        led15.setColor(BLYNK_RED);
      }
      else if (i == 16) {
        led16.setColor(BLYNK_RED);
      }
      else if (i == 17) {
        led17.setColor(BLYNK_RED);
      }
      else if (i == 18) {
        led18.setColor(BLYNK_RED);
      }
    }
  }
  for (int i = 0; i <= num_of_sensors; i++) {
    sensor_alive[i] = 0;
  }
}