Blynk.connected() always giving false. even if it is connected

I have created a sketch, but even if the blynk server is successfully connected, the Blynk.connected() results in fault, thus I am not able to check if the ESP is actually connected to the internet, nor just the WiFi. There is some nasty bug in the code, can anyone help me with that

#include <WiFiManager.h>
#include <NTPClient.h>

#define BLYNK_USE_DIRECT_CONNECT
#define min(a,b) ((a)<(b)?(a):(b))
#include <Wire.h> // must be included here so that Arduino library object file references work
#include <RtcDS1307.h>
RtcDS1307<TwoWire> Rtc(Wire);

#include <SimpleTimer.h>
#include <Adafruit_NeoMatrix.h>
#include <gamma.h>
#include <WS2812FX.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

#define BLYNK_PRINT Serial
#define LED_COUNT             64
#define LED_PIN               D3
#define BUTTON_A              D5
#define BUTTON_B              D7

#define TOTAL_STATE           6

#define START_STATE           0
#define MSG_STATE             1
#define FX_STATE              2
#define OTA_STATE             3
#define WIFI_STATE            4
#define TIME_STATE            5

#define TOTAL_TIMER           4

#define MSG_TIMER             0
#define FX_TIMER              1
#define OTA_TIMER             2
#define TIME_TIMER            3


#define BRIGHTNESS_WIDGET                 V0
#define COLOR_PICKER_WIDGET               V1
#define TEXT_SENDER_WIDGET                V2
#define TEXT_SCROLL_BUTTON_WIDGET         V3
#define FX_BUTTON_WIDGET                  V4
#define EFFECTS_WIDGET                    V5
#define MSG_SPEED_WIDGET                  V6
#define FX_SPEED_WIDGET                   V7
#define OTA_BUTTON_WIDGET                 V8
#define WIFI_CONFIG_BUTTON_WIDGET         V9
#define SHOW_TIME_BUTTON_WIDGET           V10

WidgetTerminal terminal(TEXT_SENDER_WIDGET);

char auth[] = "************";

SimpleTimer timer;

WiFiManager wifiManager;

WiFiUDP ntpUDP;

NTPClient timeClient(ntpUDP, 19800);

String msg = " ", timeIs = "";

bool otaInitilized = LOW,
     blynkConnected = LOW;

const char* host = "time.nist.gov";

uint8_t State = START_STATE,
        fxMode = 0,
        brightness = 40,
        fxSpeed = 150,
        textSpeed = 80,
        red = 255,
        green = 255,
        blue = 255;
int x = 1;
uint8_t Timer[TOTAL_TIMER];

Adafruit_NeoMatrix *matrix = new Adafruit_NeoMatrix(8, 8, D3,
    NEO_MATRIX_TOP     + NEO_MATRIX_RIGHT +
    NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE,
    NEO_GRB            + NEO_KHZ800);


WS2812FX *ws2812fx = new WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

void setup()
{
  Serial.begin(115200);
  Rtc.Begin();
  Rtc.SetSquareWavePin(DS1307SquareWaveOut_Low); 
  timeClient.begin();
  matrixInit();
  fxInit();
  otaInit();
  timerInit();
  blynkInitEvent();
}

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

void buttonAPressed()
{
  Serial.println("Button A Pressed");
}

void buttonBPressed()
{
  Serial.println("Button B Pressed");
}


void timerDisabler(int index)
{
  for (int x = 0; x < TOTAL_TIMER - 1; x++)
  {
    if (x != index)
    {
      timer.disable(Timer[x]);
    }
  }
}
#define countof(a) (sizeof(a) / sizeof(a[0]))
void printDateTime(const RtcDateTime& dt)
{
  char datestring[20];

  snprintf_P(datestring,
             countof(datestring),
             PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
             dt.Month(),
             dt.Day(),
             dt.Year(),
             dt.Hour(),
             dt.Minute(),
             dt.Second() );
  Serial.print(datestring);
}


void wifiReset()
{
  wifiManager.resetSettings();
  Blynk.virtualWrite(TEXT_SCROLL_BUTTON_WIDGET, 0);
  Blynk.virtualWrite(FX_BUTTON_WIDGET, 0);
  Blynk.virtualWrite(SHOW_TIME_BUTTON_WIDGET, 0);
  Blynk.virtualWrite(OTA_BUTTON_WIDGET, 0);
  matrix->fillScreen(0);
  matrix->setCursor(1, 1);
  matrix->setBrightness(brightness);
  matrix->setTextColor(matrix->Color(150, 150, 150));
  matrix->print("W");
  matrix->show();
  if (!wifiManager.startConfigPortal("OnDemandAP")) {
    Serial.println("failed to connect and hit timeout");
    delay(3000);
    //reset and try again, or maybe put it to deep sleep
    ESP.reset();
    delay(5000);
  }
}


void wifiSmartConfigInit()
{
  wifiManager.autoConnect();
}

void blynkInit()
{
  Blynk.virtualWrite(BRIGHTNESS_WIDGET, brightness);
  Blynk.virtualWrite(TEXT_SCROLL_BUTTON_WIDGET, LOW);
  Blynk.virtualWrite(FX_BUTTON_WIDGET, LOW);
  Blynk.virtualWrite(EFFECTS_WIDGET, 1);
  Blynk.virtualWrite(MSG_SPEED_WIDGET, textSpeed);
  Blynk.virtualWrite(FX_SPEED_WIDGET, fxSpeed);
  Blynk.virtualWrite(OTA_BUTTON_WIDGET, LOW);
  Blynk.virtualWrite(WIFI_CONFIG_BUTTON_WIDGET, LOW);
  Blynk.virtualWrite(SHOW_TIME_BUTTON_WIDGET, LOW);
  terminal.println(F(" "));
  terminal.flush();
  
}

void fxInit()
{
  ws2812fx->init();
  ws2812fx->setBrightness(brightness);
  ws2812fx->setSpeed(fxSpeed);
}

void matrixInit()
{
  matrix->begin();
  matrix->setTextWrap(false);
  matrix->setBrightness(brightness);
  matrix->fillScreen(matrix->Color(150, 150, 150));
  matrix->show();
  delay(100);
  matrix->fillScreen(0);
  matrix->show();
  x    = matrix->width();
}

void timerInit()
{
  Timer[MSG_TIMER] =  timer.setInterval(10, MSGEvent);
  timer.disable(Timer[MSG_TIMER]);
  Timer[FX_TIMER]  =  timer.setInterval(10, FXEvent);
  timer.disable(Timer[FX_TIMER]);
  timer.setInterval(10, TimeUpdateEvent);
  timer.setTimeout(5000, TimeAutoStartEvent);
  timer.setTimeout(10,blynkInitEvent);
}


void blynkInitEvent()
{
  matrix->fillScreen(0);
  matrix->show();
  // timer.disable(Timer[TIME_TIMER]);
    Blynk.config(auth);
 
  blynkConnected = HIGH;
  timer.setTimeout(1000, blynkInit);
}

void syncTime()
{
    timeClient.update();
    unsigned long secsTillEpoch = timeClient.getEpochTime() - 946684800 ;
    RtcDateTime compiled = RtcDateTime(secsTillEpoch);
    printDateTime(compiled);
    Rtc.SetDateTime(compiled);
}

void TimeUpdateEvent()
{
  RtcDateTime now = Rtc.GetDateTime();
  int hour = now.Hour();
  int minutes = now.Minute();
  int seconds = now.Second();
  String AMPM = "AM";
  if (hour == 0)
  {
    hour = 12;
  }
  if (hour > 12)
  {
    hour -= 12;
    AMPM = "PM";
  }
  timeIs = String(hour) + ":" + String(minutes) + AMPM;
 // Serial.println(timeIs + String(seconds));
}

void TimeAutoStartEvent()
{

  if (State == START_STATE)
  {
    Blynk.virtualWrite(SHOW_TIME_BUTTON_WIDGET, HIGH);
    Blynk.virtualWrite(TEXT_SCROLL_BUTTON_WIDGET, HIGH);
    State = TIME_STATE;

    timer.enable(Timer[MSG_TIMER]);
    x    = matrix->width();
    matrix->setBrightness(brightness);
  }
}

void otaInit()
{
  ArduinoOTA.onStart([]() {
    matrix->fillScreen(0);
    Serial.println("Start");
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\nEnd");
    ESP.reset();
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    matrix->setNPixelColor((progress / (total / 64)), matrix->Color(255, 0, 0));
    matrix->show();
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  });
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
    else if (error == OTA_END_ERROR) Serial.println("End Failed");
  });
}

void OTAEvent()
{
  ArduinoOTA.handle();
}

void FXEvent()
{
  if (State != START_STATE)
  {
    ws2812fx->service();
  }
}

void MSGEvent()
{
  if (State != START_STATE)
  {
    matrix->fillScreen(0);
    matrix->setCursor(x, 0);
    matrix->setTextColor(matrix->Color(red, green, blue));
    int len;
    if (State == MSG_STATE)
    {
      len = msg.length() * 6;
      matrix->print(msg);
    }
    if (State == TIME_STATE)
    {
      len = timeIs.length() * 6;
      matrix->print(timeIs);
    }

    if (--x < -len) {
      x = matrix->width();
    }
    matrix->show();
    delay(textSpeed);
  }
}

BLYNK_WRITE(BRIGHTNESS_WIDGET)
{
  brightness = param.asInt();
  if (State == MSG_STATE || State == TIME_STATE)
  {
    matrix->setBrightness(brightness);
  }
  if (State == FX_STATE)
  {
    ws2812fx->setBrightness(brightness);
  }
}

BLYNK_WRITE(COLOR_PICKER_WIDGET)
{
  red = param[0].asInt();
  green = param[1].asInt();
  blue = param[2].asInt();

  if (State == MSG_STATE)
  {
    matrix->setTextColor(matrix->Color(red, green, blue) );
  }
  if (State == FX_STATE)
  {
    ws2812fx->setColor(red, green, blue);
  }
}

BLYNK_WRITE(TEXT_SENDER_WIDGET)
{
  msg = param.asStr();
}

BLYNK_WRITE(TEXT_SCROLL_BUTTON_WIDGET)
{

  if (param.asInt() == HIGH)
  {
    State = MSG_STATE;
    timerDisabler(MSG_TIMER);
    timer.enable(Timer[MSG_TIMER]);

    x    = matrix->width();
    matrix->setBrightness(brightness);

    Blynk.virtualWrite(FX_BUTTON_WIDGET, LOW);
  }
  else
  {
    if (State != START_STATE)
    {
      State = START_STATE;
      Blynk.virtualWrite(SHOW_TIME_BUTTON_WIDGET, LOW);
      timer.disable(Timer[MSG_TIMER]);

      matrix->fillScreen(0);
      matrix->show();
    }
  }

}

BLYNK_WRITE(FX_BUTTON_WIDGET)
{
  if (param.asInt() == HIGH)
  {
    State = FX_STATE;

    timerDisabler(FX_TIMER);
    timer.enable(Timer[FX_TIMER]);

    ws2812fx->start();
    Blynk.virtualWrite(TEXT_SCROLL_BUTTON_WIDGET, LOW);
    Blynk.virtualWrite(SHOW_TIME_BUTTON_WIDGET, LOW);

  }
  else
  {
    if (State != START_STATE)
    {
      State = START_STATE;

      timer.disable(Timer[FX_TIMER]);

      ws2812fx->stop();
    }
  }


}

BLYNK_WRITE(EFFECTS_WIDGET)
{
  fxMode = param.asInt();

  ws2812fx->setMode(fxMode - 1);
}

BLYNK_WRITE(MSG_SPEED_WIDGET)
{
  textSpeed = param.asInt();
}

BLYNK_WRITE(FX_SPEED_WIDGET)
{
  fxSpeed = param.asInt();
  ws2812fx->setSpeed(fxSpeed);
}

BLYNK_WRITE(OTA_BUTTON_WIDGET)
{
  if (param.asInt() == HIGH)
  {
    State = OTA_STATE;
    for (int i = 0; i < TOTAL_TIMER; i++)
    {
      if (i != OTA_TIMER && timer.isEnabled(Timer[i]))
      {
        timer.disable(Timer[i]);
      }
    }
    if (otaInitilized == LOW)
    {
      matrix->setBrightness(brightness);
      matrix->fillScreen(0);
      matrix->setTextColor(matrix->Color(150, 150, 150));
      matrix->setCursor(1, 1);
      matrix->print("O");
      matrix->show();
      ArduinoOTA.begin();
      Timer[OTA_TIMER] = timer.setInterval(1, OTAEvent);
      otaInitilized = HIGH;
      Blynk.virtualWrite(TEXT_SCROLL_BUTTON_WIDGET, 0);
      Blynk.virtualWrite(FX_BUTTON_WIDGET, 0);
    }
    else
    {
      Blynk.virtualWrite(TEXT_SCROLL_BUTTON_WIDGET, 0);
      Blynk.virtualWrite(FX_BUTTON_WIDGET, 0);
      timer.enable(Timer[OTA_TIMER]);
    }
  }
  else
  {
    if (State != START_STATE)
    {
      State = START_STATE;
      timer.disable(Timer[OTA_TIMER]);
    }
  }
}

BLYNK_WRITE(WIFI_CONFIG_BUTTON_WIDGET)
{
//  wifiReset();
syncTime();
}

BLYNK_WRITE(SHOW_TIME_BUTTON_WIDGET)
{
  if (param.asInt() == HIGH)
  {
    State = TIME_STATE;
    textSpeed = 80;
    timerDisabler(MSG_TIMER);

    x    = matrix->width();
    timer.enable(Timer[MSG_TIMER]);
    Blynk.virtualWrite(TEXT_SCROLL_BUTTON_WIDGET, HIGH);
    Blynk.virtualWrite(FX_BUTTON_WIDGET, LOW);

  }
  else
  {
    if (State != START_STATE)
    {
      State = START_STATE;
      matrix->fillScreen(0);
      matrix->show();
      timer.disable(Timer[MSG_TIMER]);
      //timer.disable(Timer[TIME_TIMER]);
      Blynk.virtualWrite(TEXT_SCROLL_BUTTON_WIDGET, LOW);
    }
  }
}
```