BLYNK.connect() timeout event syntax

I think the bug is actually in your code, and the way that you’re using flags instead of simply doing the WiFi and Blynk connected tests each time they are needed.

You’ll see three places where there is a comment that says “Commented-out for testing”.
These if statements that are commented-out would normally prevent the sketch from attempting to connect to Blynk is there is no WiFi connection, but to prove that the Blynk.connect(timeout) functionality works correctly, we need toa allow the sketch to go ahead and attempt the connection even when the WiFi connection has been turned-off

#define BLYNK_TEMPLATE_ID "REDACTED"
#define BLYNK_DEVICE_NAME "REDACTED"
#define BLYNK_AUTH_TOKEN "REDACTED"

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// Your WiFi credentials.
char ssid[] = "REDACTED";
char pass[] = "REDACTED";

int blynk_timeout_seconds = 5;                // Timeout value for the Blynk.connect(timeout) command. The library default is 18 seconds
long check_connection_seconds = 30;           // Check the connection every 30 seconds
int wait_between_wifi_attempts_millis = 500;  // How long do we wait (in milliseconds) between each WiFi connection attempt
int max_wifi_connect_attempts = 15;           // How may times we try to connect to WiFi before giving-up 

BlynkTimer timer; 


void setup()
{
  Serial.begin(74880);
  Blynk.config(BLYNK_AUTH_TOKEN); // When we try to connect to Blynk, these are the credentials we'll use
  Connect_to_WiFi();              // Call the function that attempts to connect to WiFi

  timer.setInterval(check_connection_seconds * 1000L, Check_Connections);

  Connect_To_Blynk();             // Call the function that attempts to connect to Blynk
}

void loop()
{
//  if (WiFi.status() == WL_CONNECTED) // Commented-out for testing
  {
    if(Blynk.connected())
    {
      // Only execute Blynk.run if we are connected to Blynk
      Blynk.run();
    }
  }   
  timer.run();  // feed the timer process
}


 void Connect_to_WiFi()
{
  Serial.println(F("Connecting to Wi-Fi..."));
  
  int wifi_attempt_count = 1; // used to track how many times we've tried to connect to WiFi

  if (WiFi.status() != WL_CONNECTED)
  {
      WiFi.begin(ssid, pass); // connect to WiFi
  }

  while (WiFi.status() != WL_CONNECTED  && wifi_attempt_count < max_wifi_connect_attempts) // Loop until we've connected, or reached the maximum number of attemps allowed
  {

    Serial.print(F("Wi-Fi connection - attempt # "));
    Serial.print(wifi_attempt_count);
    Serial.print(F(" of "));
    Serial.println(max_wifi_connect_attempts); 
    timer.run();
    delay(wait_between_wifi_attempts_millis);
    timer.run();
    wifi_attempt_count++;       
  }

  // We reach this point when either we're connected to Wi-Fi, or we've reached the maximum number of attempts.
  // We need to do differnet things, depending which it is...
  if (WiFi.status() == WL_CONNECTED)
  {
    // We get here if we're connected to WiFi
    WiFi.mode(WIFI_STA); // Put the NodeMCU in Station Mode, so it doesn't broadcast its SSID
    Serial.println(F("Successfully connected to Wi-Fi"));
  }
  else
  {  
    // we get here if we tried multiple times, but can't connect to Wi-Fi. We need to go into standalone mode...
    Serial.println(F("Failed to connect to Wi-Fi"));    
  }
}


void Connect_To_Blynk()
{
//  if (WiFi.status() == WL_CONNECTED)// Commented-out for testing
  {
    // if we're connected to WiFi then try to connect to Blynk...
    Serial.println(F("Attempting to connect to Blynk..."));      
    Blynk.connect(blynk_timeout_seconds*1000);

    Serial.println(F("Blynk.connect() attempt ended"));                         // For testing 
    if(Blynk.connected())
    {
      Serial.println(F("Blynk connection attempt succeeded - connected"));       // For testing         
    }
    else
    {
      Serial.println(F("Blynk connection attempt failed - not connected"));     // For testing   
    }
  }
}


void Check_Connections() // Called with a timer 
{
  Serial.print("Checking connections.. ");
  
  if (WiFi.status() == WL_CONNECTED)
  {
    // We get here if we are connected to WiFi...
    Serial.print("WiFi Okay,  ");

    // now check if we're connected to Blynk...
    if(Blynk.connected())
    {
      Serial.println("Blynk Okay");      
    }  
    else
    {
      // We get here if we are connected to WiFi, but not to Blynk, so try to re-connect...
      Serial.println("Blynk not connected");        
      
      Connect_To_Blynk();        
    }
  }
  else
  {
    // We get here if we aren't connected to WiFi & Blynk, so try to re-connect...
    Serial.println("WiFi not connected");   
//    Connect_to_WiFi(); // Commented-out for testing
    Connect_To_Blynk();   
  }
}

The connection attempt times-out after 5 seconds if we boot-up with the WiFi turned off…

18:07:00.334 -> Wi-Fi connection - attempt # 14 of 15
18:07:00.814 -> Failed to connect to Wi-Fi
18:07:00.814 -> Attempting to connect to Blynk...
18:07:00.814 -> [24600] Connecting to blynk.cloud:80
18:07:05.835 -> Blynk.connect() attempt ended                    << Times-out after 5 seconds
18:07:05.835 -> Blynk connection attempt failed - not connected

If I boot-up with WiFi turned on, then disconnect it after around 45 seconds I get this…

18:11:08.107 -> Wi-Fi connection - attempt # 2 of 15
18:11:08.623 -> Wi-Fi connection - attempt # 3 of 15
18:11:09.140 -> Wi-Fi connection - attempt # 4 of 15
18:11:09.623 -> Wi-Fi connection - attempt # 5 of 15
18:11:10.141 -> Wi-Fi connection - attempt # 6 of 15
18:11:11.339 -> Wi-Fi connection - attempt # 7 of 15
18:11:11.855 -> Successfully connected to Wi-Fi
18:11:11.855 -> Attempting to connect to Blynk...
18:11:11.855 -> [4309] Connecting to blynk.cloud:80
18:11:11.890 -> [4368] Ready (ping: 13ms).
18:11:11.993 -> Blynk.connect() attempt ended
18:11:11.993 -> Blynk connection attempt succeeded - connected
18:11:41.847 -> Checking connections.. WiFi Okay,  Blynk Okay    << 1st test, WiFi is still on
18:12:11.869 -> Checking connections.. WiFi not connected        << 2nd test, WiFi is now off
18:12:11.869 -> Attempting to connect to Blynk...
18:12:11.869 -> [64309] Connecting to blynk.cloud:80
18:12:16.870 -> Blynk.connect() attempt ended                    << Times-out after 5 seconds
18:12:16.870 -> Blynk connection attempt failed - not connected
18:12:41.860 -> Checking connections.. WiFi not connected        << 3rd test, WiFi is still off
18:12:41.860 -> Attempting to connect to Blynk...
18:12:41.860 -> [94309] Connecting to blynk.cloud:80
18:12:46.846 -> Blynk.connect() attempt ended                    << Times-out after 5 seconds
18:12:46.846 -> Blynk connection attempt failed - not connected

Pete.