ช่วยแก้ปัญหาเวลาหน่อยครับ widget timer

ปัญหาคือ เวลาตั้งเวลา พอถึงเวลาที่ตั้งไว้ มันทำงานไม่ได้ จะติดไม่เกิน2วินาที แล้วดับครับ กับอีกอย่าง เวลาไม่ตรงกับเวลาจริง (จะเลทประมาณ30-40วินาที)

หน้าแอพครับ

#include "DHT.h"
#include <DHT.h>
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <LiquidCrystal_I2C.h>
#include <FirebaseArduino.h>
#include <time.h>

//#include <TridentTD_LineNotify.h>

LiquidCrystal_I2C lcd(0x3F, 20, 4);
#define BLYNK_PRINT Serial

// Config Firebase
//#define FIREBASE_HOST "firebaseio.com"
#define FIREBASE_AUTH "an66S55l"


int timezone = 7;
char ntp_server1[20] = "ntp.ku.ac.th";
char ntp_server2[20] = "fw.eng.ku.ac.th";
char ntp_server3[20] = "time.uni.net.th";

int dst = 0;
int Relay1 = D5;
int Relay2 = D6;
int Relay3 = D7;
int Relay4 = D8;
int Relay5 = D4;
String name;
//String smgAlertA;
//String smgAlertNew;

int setTemp;
int setHumid; 
float setHumsoil;

bool _button_ma = false;
bool _button1 = false;
bool _button2 = false;
bool _button3 = false;
bool _button4 = false;

WidgetLED led1(V30);
WidgetLED led2(V31);
WidgetLED led3(V32);
WidgetLED led4(V33);

BLYNK_WRITE(V22) //temperature slider in app on pin V22
  {
    setTemp = param.asInt();
  }

BLYNK_WRITE(V23) //hum dht22 slider in app on pin V23
  {
    setHumid = param.asInt();
  }
  
BLYNK_WRITE(V24) //hum soil slider in app on pin V24
  {
    setHumsoil = param.asInt();
  }

BLYNK_WRITE(V0) 
{
    if (param.asInt()==1) {
        _button_ma = true;
  }else{
        _button_ma = false;
  }
}
BLYNK_WRITE(V1)
{
  Serial.print("Got a value: ");
  Serial.println(param.asInt());
  
  if(param.asInt() == 0)
  {
    digitalWrite(Relay4, HIGH);
  }else{
    digitalWrite(Relay4, LOW);
  }
}
BLYNK_WRITE(V40)
{
    if (param.asInt() == 1){
        _button1 = true;
    }else{
        _button1 = false;
    }
}

BLYNK_WRITE(V41)
{
    if (param.asInt() == 1){
        _button2 = true;
    }else{
        _button2 = false;
    }
}

BLYNK_WRITE(V42)
{
    if (param.asInt() == 1){
        _button3 = true;
    }else{
        _button3 = false;
    }
}

BLYNK_WRITE(V43)
{
    if (param.asInt() == 1){
        _button4 = true;
    }else{
        _button4 = false;
    }
}
/**********************เชื่อมต่อ BLYNK SERVER CM*********************/
char auth[] = "uH_4-Y5ztaG_KtU4YrUXJxKsOldDcisu";
char ssid[] = "Wi-Fi";
char pass[] = "1212312121abc";
//char server[] = "192.168.100.101";
//int port = 8080;

BLYNK_CONNECTED() 
  {
    Blynk.syncAll();
  }

float sensorPinA = A0;
float sensorValueA;

#define DHT1PIN D3   
#define DHT1TYPE DHT22   
 
DHT dht1(DHT1PIN, DHT1TYPE);

BlynkTimer timer;

void sendsensor1() 
{
  float h1 = dht1.readHumidity();
  float t1 = dht1.readTemperature();
  t1 = dht1.readTemperature();
  t1 = t1;
  h1 = dht1.readHumidity();
  h1 = h1;
  
  float  sensorValueA = analogRead(sensorPinA);
  sensorValueA = 100 - (map(sensorValueA, 0, 1023, 0, 100));

  Blynk.virtualWrite(V11, h1);
  Blynk.virtualWrite(V10, t1);
  Blynk.virtualWrite(V12, sensorValueA);
 
}
String NowString() {
time_t now = time(nullptr);
struct tm* newtime = localtime(&now);
 
String tmpNow = "";
tmpNow += String(newtime->tm_year + 1900);
tmpNow += "-";
tmpNow += String(newtime->tm_mon + 1);
tmpNow += "-";
tmpNow += String(newtime->tm_mday);
tmpNow += " ";
tmpNow += String(newtime->tm_hour);
tmpNow += ":";
tmpNow += String(newtime->tm_min);
tmpNow += ":";
tmpNow += String(newtime->tm_sec);
return tmpNow;
}  
void setup() 
{
  Wire.begin();
  lcd.begin(16, 2);
  lcd.backlight();
  Serial.begin(9600); 
  pinMode (Relay1,OUTPUT);
  pinMode (Relay2,OUTPUT);
  pinMode (Relay3,OUTPUT);
  pinMode (Relay4,OUTPUT);
  
  digitalWrite (Relay1,HIGH);
  digitalWrite (Relay2,HIGH);
  digitalWrite (Relay3,HIGH);
  digitalWrite (Relay4,HIGH);

  Blynk.begin(auth, ssid, pass, "blynk.iot-cm.com", 8080); //ต่อserver
  
  configTime(timezone * 3600, dst, ntp_server1, ntp_server2, ntp_server3);
  Serial.println("Waiting for time");
    while (!time(nullptr)) {
      Serial.print(".");
      delay(500);
      }
Serial.println();
Serial.println("Now: " + NowString());
 
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  dht1.begin();
  timer.setInterval(2000L, sendsensor1);
   // กำหนด Line Token
//  LINE.setToken(LINE_TOKEN);
//  LINE.notify("Welcome to Farm");
}

void loop() 
{
  delay(1000);
  float h1 = dht1.readHumidity();
  float t1 = dht1.readTemperature();
  float f1 = dht1.readTemperature(true);

  float  sensorValueA = analogRead(sensorPinA);
  sensorValueA = 100 - (map(sensorValueA, 0, 1023, 0, 100));

  lcd.setCursor(0, 0);
  lcd.print("H");
  lcd.setCursor(1, 0);
  lcd.print(h1);
  lcd.setCursor(6, 0);
  lcd.print("%");

  lcd.setCursor(8, 0);
  lcd.print("T");
  lcd.setCursor(9, 0);
  lcd.print(t1);
  lcd.setCursor(14, 0);
  lcd.print("c");

  lcd.setCursor(0, 1);
  lcd.print("SH");
  lcd.setCursor(2, 1);
  lcd.print(sensorValueA);
  lcd.setCursor(7, 1);
  lcd.print("%");

/********************************auto*******************************/
if ( _button_ma == true)
{
      if (t1 >= setTemp )
        {
          digitalWrite (Relay1,LOW);
          digitalWrite (Relay2,LOW);
          led1.on();
          led2.on();
          lcd.setCursor(9, 1);
          lcd.print("SPRY ON");
          delay(1000);
        }
  else if (t1 < setTemp)
        {
          digitalWrite (Relay1,HIGH);
          digitalWrite (Relay2,HIGH);
          led1.off();
          led2.off();
          lcd.setCursor(9, 1);
          lcd.print("       ");
        }
  if (h1 <= setHumid)
        {
          digitalWrite (Relay3,LOW);
          led3.on();
          lcd.setCursor(9, 1);
          lcd.print("xxxx ON");
          delay(1000);
        }
  else if (h1 > setHumid)
        {
          digitalWrite (Relay3,HIGH);
          led3.off();
          lcd.setCursor(9, 1);
          lcd.print("       ");
        }
  if (sensorValueA <= setHumsoil)
        {
          digitalWrite (Relay4,LOW);  
          led4.on();         
          lcd.setCursor(9, 1);
          lcd.print("PUMP ON");
          delay(1000); 
        }
  else if (sensorValueA > setHumsoil)
        {
          digitalWrite (Relay4,HIGH);
          led4.off();
          lcd.setCursor(9, 1);
          lcd.print("       ");
        }
}else{   
/********************************manual*******************************/
       if (_button1 == true)
          {
            digitalWrite(Relay1, LOW);
            led1.on();
          lcd.setCursor(9, 1);
          lcd.print("SPRY ON");
          delay(1000);
          }
       else
          {
            digitalWrite(Relay1, HIGH);
            led1.off();
          lcd.setCursor(9, 1);
          lcd.print("       "); 
          }
        if (_button2 == true)
          {
            digitalWrite(Relay2, LOW);
            led2.on();
          lcd.setCursor(9, 1);
          lcd.print("FAN. ON");
          delay(1000);
          }
        else  
          {
            digitalWrite(Relay2, HIGH);
            led2.off();
          lcd.setCursor(9, 1);
          lcd.print("       ");            
          }
        if (_button3 == true)
          {
            digitalWrite(Relay3, LOW);
            led3.on();
          lcd.setCursor(9, 1);
          lcd.print("xxxx ON");
          delay(1000);            
          }
        else  
          {
            digitalWrite(Relay3, HIGH);
            led3.off();
          lcd.setCursor(9, 1);
          lcd.print("       ");                
          }
       if (_button4 == true)
          {
            digitalWrite(Relay4, LOW);
            led4.on();
          lcd.setCursor(9, 1);
          lcd.print("PUMP ON");
       //   delay(1000);             
          }
        else
          {
            digitalWrite(Relay4, HIGH);
            led4.off();
          lcd.setCursor(9, 1);
          lcd.print("       ");             
          }
}

  Serial.print(F("Humidity: "));
  Serial.print(h1);
  Serial.println(F(" % "));
  Serial.print(F("Temperature: "));
  Serial.print(t1);
  Serial.println(F(" C "));
  Serial.print(F("Soil Humidity: "));
  Serial.print(sensorValueA);
  Serial.println(F(" % "));
  Serial.println("...........................");

  StaticJsonBuffer<200> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
      root["temperature"] = t1;
      root["humidity"] = h1;
      root["soil"] = sensorValueA;
      root["time"] = NowString();
 
    // append a new value to /logDHT
        String name = Firebase.push("logDHT", root);
    // handle error
        if (Firebase.failed()) {
      Serial.print("pushing /logs failed:");
      Serial.println(Firebase.error());
      return;
}
      Serial.print("pushed: /logDHT/");
      Serial.println(name);
      delay(1000);
  Blynk.run();
  timer.run();

}

ปกติเราต้องใส่ Real-time clock ด้วยนะครับ ลองดูครับ