Error on off device for blynk edgent esp32

Helo all! Xin được mọi người giúp fix lỗi này với!! Lỗi như hình, nó cứ tự động on off lập lại hàng ngày lúc 7h AM. (router vẫn nhận được ip esp32, chỉ bị mất kết nối tới server)

Tks all!!!

/*************************************************************
#define BLYNK_TEMPLATE_ID "TMPL6N3N52L29"
#define BLYNK_TEMPLATE_NAME "Bên nhà"
//#define BLYNK_AUTH_TOKEN "Yyx1eWGfXlxOvZCt-IrW3mOfR2c5r9Q4"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
//#define USE_ESP32_DEV_MODULE
//#define USE_ESP32C3_DEV_MODULE
//#define USE_ESP32S2_DEV_KIT
//#define USE_WROVER_BOARD
//#define USE_TTGO_T7
//#define USE_TTGO_T_OI

#include "BlynkEdgent.h"
#include <TimeLib.h>
BlynkTimer timer;

bool Biencupdien = 0;   //check cup dien co lai de dieu khien hen gio

//Set up your relay pins here
const bool RelayTrigger = 0; 
struct MY_RELAY_PINS
{
  const int  RelayPin;
  const int  SwitchPin;
  bool       RelayState;
  const int  RelayVirual;
  WidgetLED  led;
};
std::vector<MY_RELAY_PINS> myRelayPins = 
{
  {23, 27, RelayTrigger, V0, V10},  // 23  den truoc choi, 27 den truoc choi
  {22, 14, RelayTrigger, V1, V11},  // 22  den trong choi, 14 den trong choi
  {21, 12, RelayTrigger, V2, V12},  // 21  den ngu, 12 den ngu
};


//***************Hen gio***********************************
const byte J = 3;
struct MY_TIMER
{
  unsigned int start1seconds[J];
  unsigned int stop1seconds[J];
  byte         dayStartSelect[J];
  byte         dayStopSelect[J];
};
std::vector<MY_TIMER> myTimer = 
{
  {0, 0, 0, 0},
  {0, 0, 0, 0},
  {0, 0, 0, 0},
};

char ClockTime[16];                // Char Array to hold current time
char ClockDate[16];
unsigned int daySeconds;
byte today;
//==================================================================

void setup()
{
  Serial.begin(115200);
  delay(100);
  for (int i =0; i<myRelayPins.size(); i++){
  pinMode(myRelayPins[i].RelayPin, OUTPUT);
  pinMode(myRelayPins[i].SwitchPin, INPUT_PULLUP);
  digitalWrite(myRelayPins[i].RelayPin, myRelayPins[i].RelayState);
  }

  BlynkEdgent.begin();
  timer.setInterval(300000UL, temp);
  timer.setTimeout(5000L, []() {
    timer.setInterval(3000L, timeChecker);
  });
}

void loop() {
  BlynkEdgent.run();
  timer.run();
  Blynk.sendInternal("rtc", "sync");
}

//===================================

BLYNK_CONNECTED() {
  // Request the latest state from the server
   Blynk.sendInternal("rtc", "sync");
  Blynk.syncAll();
}

void temp(){
  //fix err timer.setInterval... id 0
}


//               retart VDK
BLYNK_WRITE(V99){
  if (param.asInt()){
    ESP.restart();
    delay(2000);
  }
}
// When App button is pushed - switch the state

BLYNK_WRITE(V0) {
  myRelayPins[0].RelayState = param.asInt();
  digitalWrite(myRelayPins[0].RelayPin, myRelayPins[0].RelayState);
  if (myRelayPins[0].RelayState == !RelayTrigger){
    myRelayPins[0].led.on();
  }
  else {
    myRelayPins[0].led.off();
  }
}

BLYNK_WRITE(V1) {
  myRelayPins[1].RelayState = param.asInt();
  digitalWrite(myRelayPins[1].RelayPin, myRelayPins[1].RelayState);
  if (myRelayPins[1].RelayState == !RelayTrigger){
    myRelayPins[1].led.on();
  }
  else {
    myRelayPins[1].led.off();
  }
}

BLYNK_WRITE(V2) {
  myRelayPins[2].RelayState = param.asInt();
  digitalWrite(myRelayPins[2].RelayPin, myRelayPins[2].RelayState);
  if (myRelayPins[2].RelayState == !RelayTrigger){
    myRelayPins[2].led.on();
  }
  else {
    myRelayPins[2].led.off();
  }
}

//============================
BLYNK_WRITE(InternalPinRTC){
  const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013
  unsigned long blynkTime = param.asLong();
  if (blynkTime >= DEFAULT_TIME) {
  setTime(blynkTime);
  today= weekday();
  daySeconds = (hour()*3600) + (minute()*60) + second();
  //Serial.println(String("Time: ") + daySecond);
  //Serial.println(String("day: ") + today);
  sprintf(ClockTime, "%02d:%02d:%02d", hour(), minute(), second());
  sprintf(ClockDate, "%02d:%02d:%02d", day(), month(), year());
  Blynk.virtualWrite(V20, ClockTime);
  Blynk.virtualWrite(V21, ClockDate);
  setSyncInterval(3600);
  }
}


void timeChecker() {   // daySeconds is actual elapsed seconds since midnight
  //----------------------------------------------------------------- 
  for (int i = 0; i< myTimer.size(); i++){
   for (int j = 0; j<J; j++){
    if (Biencupdien == 1){
    if ((myRelayPins[i].RelayState == RelayTrigger) && (bitRead(myTimer[i].dayStartSelect[j], today))){      //  time start 
        if((daySeconds >= myTimer[i].start1seconds[j])&&(daySeconds <= myTimer[i].start1seconds[j] + 3)){
          Blynk.virtualWrite(myRelayPins[i].RelayVirual, !RelayTrigger);
          Blynk.syncVirtual(myRelayPins[i].RelayVirual);
        }
      }

   if ((myRelayPins[i].RelayState == !RelayTrigger) && (bitRead(myTimer[i].dayStopSelect[j],  today))){  //time stop  
      if((daySeconds >= myTimer[i].stop1seconds[j])&&(daySeconds <= myTimer[i].stop1seconds[j] + 3)) {
        Blynk.virtualWrite(myRelayPins[i].RelayVirual, RelayTrigger);
        Blynk.syncVirtual(myRelayPins[i].RelayVirual);
      }  
     }
    }
    else {
      if ((myRelayPins[i].RelayState == RelayTrigger) && (bitRead(myTimer[i].dayStartSelect[j], today))){      //  time start 
        if((daySeconds >= myTimer[i].start1seconds[j]) && (daySeconds < myTimer[i].stop1seconds[j])){
          Blynk.virtualWrite(myRelayPins[i].RelayVirual, !RelayTrigger);
          Blynk.syncVirtual(myRelayPins[i].RelayVirual);
        }
      }

     if ((myRelayPins[i].RelayState == !RelayTrigger) && (bitRead(myTimer[i].dayStopSelect[j],  today))){  //time stop  
       if(daySeconds >= myTimer[i].stop1seconds[j]) {
         Blynk.virtualWrite(myRelayPins[i].RelayVirual, RelayTrigger);
         Blynk.syncVirtual(myRelayPins[i].RelayVirual);
       }  
     }
     if (i == (myTimer.size()-1)){
       Biencupdien = 1;
     }
   }
  }
 }
}

//------------------------------------------------------------
BLYNK_WRITE(V30) {      // den truoc choi             moc time 1   
  TimeInputParam t(param);
  for (int i = 1; i <= 7; i++)
    if (t.isWeekdaySelected(i))
      if (i == 7)
      {
        bitWrite(myTimer[0].dayStartSelect[0], 1,   1);
        bitWrite(myTimer[0].dayStopSelect[0],  1,   1);
      }
      else
      {
        bitWrite(myTimer[0].dayStartSelect[0], i + 1, 1);
        bitWrite(myTimer[0].dayStopSelect[0],  i + 1, 1);
      }
    
  
 
 
    if (param[0].asLong())                                             // Process start time
    {
      myTimer[0].start1seconds[0] = param[0].asLong();
    }
    else {
      myTimer[0].start1seconds[0] = 1000000;
    }
    if (param[1].asLong())                                              // Process stop time
    {
      myTimer[0].stop1seconds[0] = param[1].asLong();    
    }
    else {
      myTimer[0].stop1seconds[0] = 1000000;
    }
}
BLYNK_WRITE(V31) {      // den truoc choi                moc time 2   
  TimeInputParam t(param);
  for (int i = 1; i <= 7; i++)
    if (t.isWeekdaySelected(i))
      if (i == 7)
      {
        bitWrite(myTimer[0].dayStartSelect[1], 1,   1);
        bitWrite(myTimer[0].dayStopSelect[1],  1,   1);
      }
      else
      {
        bitWrite(myTimer[0].dayStartSelect[1], i + 1, 1);
        bitWrite(myTimer[0].dayStopSelect[1],  i + 1, 1);
      }
    
 
    if (param[0].asLong())                                             // Process start time
    {
      myTimer[0].start1seconds[1] = param[0].asLong();
    }
    else {
      myTimer[0].start1seconds[1] = 1000000;
    }
    if (param[1].asLong())                                              // Process stop time
    {
      myTimer[0].stop1seconds[1] = param[1].asLong();    
    }
    else {
      myTimer[0].stop1seconds[1] = 1000000;
    }
}

BLYNK_WRITE(V32) {      // den truoc choi               moc time 3  
  TimeInputParam t(param);
  for (int i = 1; i <= 7; i++)
    if (t.isWeekdaySelected(i))
      if (i == 7)
      {
        bitWrite(myTimer[0].dayStartSelect[2], 1,   1);
        bitWrite(myTimer[0].dayStopSelect[2],  1,   1);
      }
      else
      {
        bitWrite(myTimer[0].dayStartSelect[2], i + 1, 1);
        bitWrite(myTimer[0].dayStopSelect[2],  i + 1, 1);
      }
    
 
    if (param[0].asLong())                                             // Process start time
    {
      myTimer[0].start1seconds[2] = param[0].asLong();
    }
    else {
      myTimer[0].start1seconds[2] = 1000000;
    }
    if (param[1].asLong())                                              // Process stop time
    {
      myTimer[0].stop1seconds[2] = param[1].asLong();    
    }
    else {
      myTimer[0].stop1seconds[2] = 1000000;
    }
}

//==============================
BLYNK_WRITE(V40) {      // den truoc choi             moc time 1   
  TimeInputParam t(param);
  for (int i = 1; i <= 7; i++)
    if (t.isWeekdaySelected(i))
      if (i == 7)
      {
        bitWrite(myTimer[1].dayStartSelect[0], 1,   1);
        bitWrite(myTimer[1].dayStopSelect[0],  1,   1);
      }
      else
      {
        bitWrite(myTimer[1].dayStartSelect[0], i + 1, 1);
        bitWrite(myTimer[1].dayStopSelect[0],  i + 1, 1);
      }
  
 
 
    if (param[0].asLong())                                             // Process start time
    {
      myTimer[1].start1seconds[0] = param[0].asLong();
    }
    else {
      myTimer[1].start1seconds[0] = 1000000;
    }
    if (param[1].asLong())                                              // Process stop time
    {
      myTimer[1].stop1seconds[0] = param[1].asLong();    
    }
    else {
      myTimer[1].stop1seconds[0] = 1000000;
    }
}
BLYNK_WRITE(V41) {      // den truoc choi                moc time 2   
  TimeInputParam t(param);
  for (int i = 1; i <= 7; i++)
    if (t.isWeekdaySelected(i))
      if (i == 7)
      {
        bitWrite(myTimer[1].dayStartSelect[1], 1,   1);
        bitWrite(myTimer[1].dayStopSelect[1],  1,   1);
      }
      else
      {
        bitWrite(myTimer[1].dayStartSelect[1], i + 1, 1);
        bitWrite(myTimer[1].dayStopSelect[1],  i + 1, 1);
      }
  
 
 
    if (param[0].asLong())                                             // Process start time
    {
      myTimer[1].start1seconds[1] = param[0].asLong();
    }
    else {
      myTimer[1].start1seconds[1] = 1000000;
    }
    if (param[1].asLong())                                              // Process stop time
    {
      myTimer[1].stop1seconds[1] = param[1].asLong();    
    }
    else {
      myTimer[1].stop1seconds[1] = 1000000;
    }
}

BLYNK_WRITE(V42) {      // den truoc choi               moc time 3  
  TimeInputParam t(param);
  for (int i = 1; i <= 7; i++)
    if (t.isWeekdaySelected(i))
      if (i == 7)
      {
        bitWrite(myTimer[1].dayStartSelect[2], 1,   1);
        bitWrite(myTimer[1].dayStopSelect[2],  1,   1);
      }
      else
      {
        bitWrite(myTimer[1].dayStartSelect[2], i + 1, 1);
        bitWrite(myTimer[1].dayStopSelect[2],  i + 1, 1);
      }
  
 
 
    if (param[0].asLong())                                             // Process start time
    {
      myTimer[1].start1seconds[2] = param[0].asLong();
    }
    else {
      myTimer[1].start1seconds[2] = 1000000;
    }
    if (param[1].asLong())                                              // Process stop time
    {
      myTimer[1].stop1seconds[2] = param[1].asLong();    
    }
    else {
      myTimer[1].stop1seconds[2] = 1000000;
    }
}

//==============================
BLYNK_WRITE(V50) {      // den truoc choi             moc time 1   
  TimeInputParam t(param);
  for (int i = 1; i <= 7; i++)
    if (t.isWeekdaySelected(i))
      if (i == 7)
      {
        bitWrite(myTimer[2].dayStartSelect[0], 1,   1);
        bitWrite(myTimer[2].dayStopSelect[0],  1,   1);
      }
      else
      {
        bitWrite(myTimer[2].dayStartSelect[0], i + 1, 1);
        bitWrite(myTimer[2].dayStopSelect[0],  i + 1, 1);
      }
  
 
 
    if (param[0].asLong())                                             // Process start time
    {
      myTimer[2].start1seconds[0] = param[0].asLong();
    }
    else {
      myTimer[2].start1seconds[0] = 1000000;
    }
    if (param[1].asLong())                                              // Process stop time
    {
      myTimer[2].stop1seconds[0] = param[1].asLong();    
    }
    else {
      myTimer[2].stop1seconds[0] = 1000000;
    }
}
BLYNK_WRITE(V51) {      // den truoc choi                moc time 2   
  TimeInputParam t(param);
  for (int i = 1; i <= 7; i++)
    if (t.isWeekdaySelected(i))
      if (i == 7)
      {
        bitWrite(myTimer[2].dayStartSelect[1], 1,   1);
        bitWrite(myTimer[2].dayStopSelect[1],  1,   1);
      }
      else
      {
        bitWrite(myTimer[2].dayStartSelect[1], i + 1, 1);
        bitWrite(myTimer[2].dayStopSelect[1],  i + 1, 1);
      }
  
 
 
    if (param[0].asLong())                                             // Process start time
    {
      myTimer[2].start1seconds[1] = param[0].asLong();
    }
    else {
      myTimer[2].start1seconds[1] = 1000000;
    }
    if (param[1].asLong())                                              // Process stop time
    {
      myTimer[2].stop1seconds[1] = param[1].asLong();    
    }
    else {
      myTimer[2].stop1seconds[1] = 1000000;
    }
}

BLYNK_WRITE(V52) {      // den truoc choi               moc time 3  
  TimeInputParam t(param);
  for (int i = 1; i <= 7; i++)
    if (t.isWeekdaySelected(i))
      if (i == 7)
      {
        bitWrite(myTimer[2].dayStartSelect[2], 1,   1);
        bitWrite(myTimer[2].dayStopSelect[2],  1,   1);
      }
      else
      {
        bitWrite(myTimer[2].dayStartSelect[2], i + 1, 1);
        bitWrite(myTimer[2].dayStopSelect[2],  i + 1, 1);
      }
  
 
 
    if (param[0].asLong())                                             // Process start time
    {
      myTimer[2].start1seconds[2] = param[0].asLong();
    }
    else {
      myTimer[2].start1seconds[2] = 1000000;
    }
    if (param[1].asLong())                                              // Process stop time
    {
      myTimer[2].stop1seconds[2] = param[1].asLong();    
    }
    else {
      myTimer[2].stop1seconds[2] = 1000000;
    }
}

This looks like your ISP dropping the WAN side connection every day. Some ISPs do this to free-up the pool of external IP addresses.
Do other devices lose internet connectivity for a second or two when this happens, and does your external (public IP address change each day at this time?

Also you MUST remove this line from your void loop…

This is causing the device to send a sync request to the Blynk server thousands of times per second.

Pete.

Hi!! Tks!!
Các thiếp bị khác vẫn kết nối ok, bạn!!

You cannot have this in your void loop!

Pete.

Tôi đã làm theo khuyến nghị của bạn!! Tks Pete!!!

Helo Pete!
tôi có thể thay BlynkSimpleEsp32_SSL.h trong edgent thành BlynkSimpleEsp32.h đc ko? vì tôi phát hiện lỗi auto on off hôm bữa do thư viện này.
Tks Pete

You’ve asked the same question in another topic,so I’m closing this one.

Pete.