Blynk takes 3-4 seconds to connect to server

No. Actualy local network connection almost instant. Blynk connection takes 5secs.

Current setup sketch:

  Serial.println("Connecting to local network");
  
  // Setup WiFi network
  WiFi.config(ip, gateway, subnet, dns1, dns2);
  WiFi.begin(ssid, password, 10, router_mac);

  while (WiFi.status() != WL_CONNECTED) {
    delay(20);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  // Setup Blynk
  Blynk.config(auth, blynk_server_ip);
  while (Blynk.connect() == false) {
    Serial.print(".");
  }

  Serial.println("Connected to Blynk server");

And here is the debug output:

Blynk connection takes about 5 seconds.

Connecting to local network
........
Connected to YANIK2
IP address: 192.168.1.77
[425] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.3 on ESP8266

[431] Free RAM: 44272
[5001] Connecting to 77.223.144.76
[5058] <[02|00|01|00] APIKEY
[5119] >[00|00|01|00]�
[5119] Ready (ping: 2ms).
[5119] <[11|00|01|00]Gver[00]0.4.3[00]h-beat[00]10[00]buff-in[00]256[00]dev[00]ESP8266[00]build[00]Jan 15 2017 14:58:19[00]
Connected to Blynk server
[5181] >[00|00|01|00]�

This is where connection to server starts.

Yesterday I’ve tried the same with my esp12e and a low power weather station with bme280 and I have your same time results

1 Like

I think you are right but why 5 seconds from showing free RAM to trying to connect to the server?

I found the problem.

This line cause the 5secs delay:

If I change 5000UL to 1000UL delay reducing to 1sec.

5 Likes

@hamityanik nice hack, set mine to 500 so about 550ms to 650ms to connect to the server from reboot.

[301] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.4 on ESP8266

[501] Connecting to 192.168.10.229
[625] Ready (ping: 8ms).
Connected to Blynk server

I’ve added
lastLogin = 99999;

after this line, and problem gone. (at least for now :slight_smile: )

It will be like this:
this->authkey = auth; lastLogin = 99999;

5 Likes

Fantastic work investigating this @hamityanik

1 Like

@vshymanskyy please explain purpose of this 5000L delay.

1 Like

Yes we limit reconnection time - minimum 5 seconds delay.

for what purpose?

is it OK for Local Server user to bypass this delay?

Yes, you can modify the library as you want.

1 Like

@vshymanskyy,
Are there other tricks like this one for Local Server to do it even better?

Thanks!!

can be possible to convert this reconnection time with an “antiflood like” system?

'cause a battery powered system need 1 connection at xx minutes to make a low energy purpose, instead of a “normal” system that turn on and stay on…

Battery powered systems are recommended to use our HTTP API

3 Likes

I’ve written another code for my project, it uses HTTP API but, I think there is no way to update “last seen” section via HTTP API. Device seems always offline. Is there anyway?

@Dmitriy, check this out…

1 Like

What exactly?

I’m talking about this