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.

I’m sorry I haven’t been able to reply for a few days.

There is a big difference between the definitions of “no wifi connection” and “no internet”.
In my screenshots above, I indicated that I was turning off the Internet, and not turning off the wifi connection.
Yes, indeed, if you break the Wi-Fi connection, then the specified timeout - 5 seconds - is true.
But! If you leave the router turned on and the wifi is active, but you break the Internet connection, then the timeout will always be 18 seconds.
This is significant! It is important for me that when the Internet connection is broken, my controller does not freeze for a long time, but performs other important functions (except for Blynk).

That is why I say that the function Blynk.connect(timeout)contains a bug.

I’m not saying it doesn’t work. I’m saying that when the internet connection is broken, the actual timeout in the function is 18 seconds, not the time you specify.

Try to check first if DNS servers are correctly configured, before trying to connect Blynk. This will give you a signal of DHCP working correctly.
Maybe using Wifi.config before Wifi.begin in your program
https://www.arduino.cc/reference/en/libraries/wifi/wifi.config/

I have no problem connecting to the Blynk server.
I specifically break the Internet connection in order to check the real timeout in the Blynk.connected(timeout) function, and it does not match the set one.
Therefore, I don’t understand where the DNS and DHCP have to do with it …

I’ve done some more testing with the example sketch I posted above in post #31, this time leaving the wireless access point switched-on and pulling the LAN cable out of the back. This keeps the WiFi connection between the device and the WAP, but kills the internet connection.

It still works as expected.
I’ve added comments , which look like this: <<< my comment in here >>> to explain what is happening at each stage…

09:01:10.945 ->     ___  __          __
09:01:10.945 ->    / _ )/ /_ _____  / /__
09:01:10.945 ->   / _  / / // / _ \/  '_/
09:01:10.945 ->  /____/_/\_, /_//_/_/\_\
09:01:10.945 ->         /___/ v1.1.0 on ESP8266
09:01:10.945 -> 
09:01:10.945 ->  #StandWithUkraine    https://bit.ly/swua
09:01:10.945 -> 
09:01:10.945 -> 
09:01:10.945 -> Connecting to Wi-Fi...
09:01:10.945 -> Wi-Fi connection - attempt # 1 of 15
09:01:11.422 -> Wi-Fi connection - attempt # 2 of 15
09:01:11.941 -> Wi-Fi connection - attempt # 3 of 15
09:01:12.419 -> Wi-Fi connection - attempt # 4 of 15
09:01:12.931 -> Wi-Fi connection - attempt # 5 of 15
09:01:13.442 -> Wi-Fi connection - attempt # 6 of 15
09:01:14.640 -> Wi-Fi connection - attempt # 7 of 15
09:01:15.158 -> Successfully connected to Wi-Fi
09:01:15.158 -> Attempting to connect to Blynk...
09:01:15.158 -> [4312] Connecting to blynk.cloud:80
09:01:15.193 -> [4350] Ready (ping: 16ms).
09:01:15.262 -> Blynk.connect() attempt ended
09:01:15.262 -> Blynk connection attempt succeeded - connected
09:01:45.144 -> Checking connections.. WiFi Okay,  Blynk Okay
09:02:15.139 -> Checking connections.. WiFi Okay,  Blynk Okay
09:02:45.172 -> Checking connections.. WiFi Okay,  Blynk Okay

<<< LAN plug pulled at around 09:03:00 Blynk.connected() still returns true, because no heartbeat timeout yet... >>>

09:03:15.162 -> Checking connections.. WiFi Okay,  Blynk Okay
09:03:45.173 -> Checking connections.. WiFi Okay,  Blynk Okay

 <<< Heartbeat interval for this device is 45 seconds, heartbeat times-out around 48 seconds after the internet connection is cut... >>>

09:03:48.289 -> [157430] Heartbeat timeout

<< Now reports that WiFi is connected but Blynk is not - this is correct... >>>

09:04:15.154 -> Checking connections.. WiFi Okay,  Blynk not connected

<<< Because Blynk is not connected the sketch attempts to reconnect to Blynk. This fails, because no internet connection. Connection attempt times-out after 6.220 seconds... >>>

09:04:15.154 -> Attempting to connect to Blynk...
09:04:15.154 -> [184311] Connecting to blynk.cloud:80
09:04:21.383 -> Blynk.connect() attempt ended
09:04:21.383 -> Blynk connection attempt failed - not connected

<<< Attempts to connect to Blynk again, this time the timeout is 6.235 seconds... >>>

09:04:45.170 -> Checking connections.. WiFi Okay,  Blynk not connected
09:04:45.170 -> Attempting to connect to Blynk...
09:04:45.170 -> [214311] Connecting to blynk.cloud:80
09:04:51.405 -> Blynk.connect() attempt ended
09:04:51.405 -> Blynk connection attempt failed - not connected

<<< Attempts to connect to Blynk again, this time the timeout is 6.233 seconds... >>>

09:05:15.165 -> Checking connections.. WiFi Okay,  Blynk not connected
09:05:15.165 -> Attempting to connect to Blynk...
09:05:15.165 -> [244311] Connecting to blynk.cloud:80
09:05:21.398 -> Blynk.connect() attempt ended
09:05:21.398 -> Blynk connection attempt failed - not connected

The timeout periods are slightly longer than the 5 seconds specified in the Blynk.connect(timeout) command, but I think that’s to be expected.

Pete.

@Serg_Grn would you go to Blynk Console > Your Device > Device Info and tell me what it shows for Board Type and Heartbeat Interval ?

Pete.

BOARD TYPE: ESP32
HEARTBEAT INTERVAL: 45

I don’t understand why your code example works and mine doesn’t. The code is very simple.
And why if you break the connection to the Internet, the timeout from 5 seconds turns into 18 seconds - I don’t understand either …
Maybe there is a difference in the libraries for esp8266 and esp32?

I re-tested with an ESP32 and the results were the same.

I 've not sent a lot of time un-picking your code, but I don’t like the way that it uses flags instead of simply doing the tests of whether WiFi and Blynk are connected.

Does my code work for you and produce the same results?

Pete.

I can only check it tomorrow.

Is there any violation in periodically writing the status to a variable, and then using it in a loop? It seemed to me that this was a simple and convenient solution … And I did not find anything in the documentation that would contradict this.

No, it just adds a degree of complexity to a process that already has quite a few factors to understand when testing. I’d prefer to keep the code structured into chunks that have a clearly defined functions and not have to track the status of a number of flag variables that can easily be eliminated.

Pete.

Here is the result of the test, your code is completely used, I only changed the library from 8266 to 32:

11:44:40.860 ->     ___  __          __
11:44:40.860 ->    / _ )/ /_ _____  / /__
11:44:40.860 ->   / _  / / // / _ \/  '_/
11:44:40.860 ->  /____/_/\_, /_//_/_/\_\
11:44:40.860 ->         /___/ v1.0.1 on ESP32
11:44:40.860 -> 
11:44:40.860 -> Connecting to Wi-Fi...
11:44:40.956 -> Wi-Fi connection - attempt # 1 of 15
11:44:41.481 -> Wi-Fi connection - attempt # 2 of 15
11:44:41.958 -> Wi-Fi connection - attempt # 3 of 15
11:44:42.483 -> Wi-Fi connection - attempt # 4 of 15
11:44:42.960 -> Wi-Fi connection - attempt # 5 of 15
11:44:43.488 -> Successfully connected to Wi-Fi
11:44:43.488 -> Attempting to connect to Blynk...
11:44:43.488 -> [2645] Connecting to blynk.cloud:80
11:44:43.677 -> [2868] Ready (ping: 101ms).
11:44:43.773 -> Blynk.connect() attempt ended
11:44:43.773 -> Blynk connection attempt succeeded - connected
11:45:13.488 -> Checking connections.. WiFi Okay,  Blynk Okay
11:45:43.470 -> Checking connections.. WiFi Okay,  Blynk Okay
11:46:13.458 -> Checking connections.. WiFi Okay,  Blynk Okay
11:46:43.455 -> Checking connections.. WiFi Okay,  Blynk Okay
11:47:13.455 -> Checking connections.. WiFi Okay,  Blynk Okay
11:47:16.808 -> [155997] Heartbeat timeout
11:47:43.470 -> Checking connections.. WiFi Okay,  Blynk not connected
11:47:43.470 -> Attempting to connect to Blynk...
11:47:43.470 -> [182645] Connecting to blynk.cloud:80
11:48:01.985 -> Blynk.connect() attempt ended
11:48:01.985 -> Blynk connection attempt failed - not connected
11:48:13.465 -> Checking connections.. WiFi Okay,  Blynk not connected
11:48:13.465 -> Attempting to connect to Blynk...
11:48:13.465 -> [212645] Connecting to blynk.cloud:80
11:48:31.967 -> Blynk.connect() attempt ended
11:48:31.967 -> Blynk connection attempt failed - not connected
11:48:43.451 -> Checking connections.. WiFi Okay,  Blynk not connected
11:48:43.499 -> Attempting to connect to Blynk...
11:48:43.499 -> [242645] Connecting to blynk.cloud:80
11:49:01.976 -> Blynk.connect() attempt ended
11:49:01.976 -> Blynk connection attempt failed - not connected

Those 18 seconds…
Here is the code itself:

#define BLYNK_TEMPLATE_ID "---"
#define BLYNK_DEVICE_NAME "---"
#define BLYNK_AUTH_TOKEN "---"

#define BLYNK_PRINT Serial

#include <WiFi.h> 
#include <WiFiClient.h> 
#include <BlynkSimpleEsp32.h>

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

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();   
  }
}

As you can see, the reason is not “wrong code” but something else…

What version of the ESP32 core are you using?

Do you have an ESP8266 you can test it with?

Pete.

Using ESP object:
v3.3.5-1-g85c43024c

If I find 8266, I’ll check.

Test result, your code and esp8266.
Now I got the same 6 seconds as in your tests.

14:25:47.010 ->     ___  __          __
14:25:47.010 ->    / _ )/ /_ _____  / /__
14:25:47.010 ->   / _  / / // / _ \/  '_/
14:25:47.010 ->  /____/_/\_, /_//_/_/\_\
14:25:47.010 ->         /___/ v1.0.1 on ESP8266
14:25:47.010 -> 
14:25:47.010 -> Connecting to Wi-Fi...
14:25:47.010 -> Wi-Fi connection - attempt # 1 of 15
14:25:47.485 -> Wi-Fi connection - attempt # 2 of 15
14:25:48.000 -> Wi-Fi connection - attempt # 3 of 15
14:25:48.519 -> Wi-Fi connection - attempt # 4 of 15
14:25:48.984 -> Wi-Fi connection - attempt # 5 of 15
14:25:49.496 -> Wi-Fi connection - attempt # 6 of 15
14:25:50.719 -> Wi-Fi connection - attempt # 7 of 15
14:25:51.234 -> Wi-Fi connection - attempt # 8 of 15
14:25:51.702 -> Successfully connected to Wi-Fi
14:25:51.750 -> Attempting to connect to Blynk...
14:25:51.750 -> [4794] Connecting to blynk.cloud:80
14:25:51.842 -> [4936] Ready (ping: 65ms).
14:25:51.936 -> Blynk.connect() attempt ended
14:25:51.936 -> Blynk connection attempt succeeded - connected
14:26:21.720 -> Checking connections.. WiFi Okay,  Blynk Okay
14:26:51.729 -> Checking connections.. WiFi Okay,  Blynk Okay
14:27:21.718 -> Checking connections.. WiFi Okay,  Blynk Okay
14:27:51.734 -> Checking connections.. WiFi Okay,  Blynk Okay
14:28:21.734 -> Checking connections.. WiFi Okay,  Blynk Okay
14:28:25.011 -> [158065] Heartbeat timeout
14:28:51.702 -> Checking connections.. WiFi Okay,  Blynk not connected
14:28:51.748 -> Attempting to connect to Blynk...
14:28:51.748 -> [184794] Connecting to blynk.cloud:80
14:28:57.955 -> Blynk.connect() attempt ended
14:28:57.955 -> Blynk connection attempt failed - not connected
14:29:21.739 -> Checking connections.. WiFi Okay,  Blynk not connected
14:29:21.739 -> Attempting to connect to Blynk...
14:29:21.739 -> [214794] Connecting to blynk.cloud:80
14:29:27.986 -> Blynk.connect() attempt ended
14:29:27.986 -> Blynk connection attempt failed - not connected
14:29:51.733 -> Checking connections.. WiFi Okay,  Blynk not connected
14:29:51.733 -> Attempting to connect to Blynk...
14:29:51.733 -> [244794] Connecting to blynk.cloud:80
14:29:57.991 -> Blynk.connect() attempt ended
14:29:57.991 -> Blynk connection attempt failed - not connected
14:30:21.717 -> Checking connections.. WiFi Okay,  Blynk not connected
14:30:21.717 -> Attempting to connect to Blynk...
14:30:21.717 -> [274794] Connecting to blynk.cloud:80
14:30:27.989 -> Blynk.connect() attempt ended
14:30:27.989 -> Blynk connection attempt failed - not connected

The time - 6 seconds - instead of the advertised 5, seems strange. Where does one more second come from? For a controller, 1 second is a huge amount of time…

Not sure what that means.
My tests were done with ESP32 core version 2.0.5

It’s also worth checking which versions of WiFi.h is being used when the sketch is compiled, and ensuring that it’s v2.0.0 one from the ESP32 Core 2.0.5 folder…

Multiple libraries were found for “WiFi.h”
Used: C:\Users\Pete Knight\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5\libraries\WiFi
Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
Not used: C:\Users\Pete Knight\Documents\Arduino\libraries\WiFiNINA
Using library WiFi at version 2.0.0 in folder: C:\Users\Pete Knight\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5\libraries\WiFi

Pete.

1 Like

I misunderstood your question.
This is what esp32 returns when called ESP.getSdkVersion()

The esp version in the board manager is 1.0.6, the newer version is not in the list.
Maybe I need to update the IDE, what version do you have?

You are probably using an old URL in the Preferences > Additional Boards Manager URLs setting.
It should be the one shown in the Stable release link of this guide…

https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html

Once you’ve done that you should see a new list of release versions in the Boards Manager.

Pete.

1 Like

Yes, that was the reason.
Now the function takes the same 6 seconds as in your tests.

15:51:20.215 -> Checking connections.. WiFi Okay,  Blynk Okay
15:51:50.194 -> Checking connections.. WiFi Okay,  Blynk Okay
15:51:53.832 -> [155419] Heartbeat timeout
15:52:20.187 -> Checking connections.. WiFi Okay,  Blynk not connected
15:52:20.187 -> Attempting to connect to Blynk...
15:52:20.234 -> [181812] Connecting to blynk.cloud:80
15:52:26.463 -> Blynk.connect() attempt ended
15:52:26.463 -> Blynk connection attempt failed - not connected
15:52:50.224 -> Checking connections.. WiFi Okay,  Blynk not connected
15:52:50.224 -> Attempting to connect to Blynk...
15:52:50.224 -> [211812] Connecting to blynk.cloud:80
15:52:56.454 -> Blynk.connect() attempt ended
15:52:56.454 -> Blynk connection attempt failed - not connected

Thank you very much for your time and help in solving the problem! :pray:

If it’s not difficult, could you say why the time is not 5 seconds, but 6, does it really take so long to exchange data via wifi? …
This question is no longer so important, I’m just asking out of curiosity and in order to understand the ongoing processes a little more…

Thanks again!

Glad it’s working!

I’m not sure. I know it’s always fairly approximate, and I guess you can reduce the number slightly to get the result you need, but obviously if you go too low then it won’t connect to Blynk before it times-out.

Pete.

1 Like