Taking too long to connect to server

Arduino UNO with Ethernet Shield
• Smartphone OS (Android) 2.27.32
• Blynk server
• v0.6.7 on Arduino Uno

#include "iot.h"
#include <SPI.h>
//#include <Ethernet2.h>
#include <BlynkSimpleEthernet2.h>

const char auth[] = "auth token here ;

unsigned long tim_blynk = 0,
              tim_alert = 0,
              tim_main = 0,
              tim_update = 0;
bool reset_eth = false;

void init_ac_input()
{
    // pinMode(UPS_IN, INPUT_PULLUP);
    pinMode(MAIN_IN, INPUT);
    pinMode(RELAY_BUZZER, OUTPUT);
    digitalWrite(RELAY_BUZZER, HIGH);
}

void reset_ETH()
{
    pinMode(A1, OUTPUT);
    delay(100);
    digitalWrite(A1, LOW);
    delay(1000);
    digitalWrite(A1, HIGH);
    delay(100);
    DEBUG("Reset ETH");
}

void monitor()
{
    if (millis() < tim_main)
    {
        tim_main = millis();
        tim_alert = millis();
        tim_update = millis();
    }

    if (!digitalRead(MAIN_IN) && millis() - tim_main > MAIN_ALERT_TIME_MS)
    {
        digitalWrite(RELAY_BUZZER, LOW);
    }
    else if (digitalRead(MAIN_IN))
    {
        digitalWrite(RELAY_BUZZER, HIGH);
        tim_main = millis();
    }

    if (!digitalRead(MAIN_IN) && millis() - tim_alert > 120000)
    {
        tim_alert = millis();
        DEBUG("Not present");
        //Blynk.notify("UPS Main Power is lost");
    }

    if (millis() - tim_update > 2000)
    {
        tim_update = millis();

        if (digitalRead(MAIN_IN))
        {
            Blynk.virtualWrite(V0, "UPS OK");
            Blynk.setProperty(V0, "color", "#23C48E");
        }
        else
        {
            Blynk.setProperty(V0, "color", "#D3435C");
            Blynk.virtualWrite(V0, "UPS Fault");
        }
    }
}

void init_blynk()
{
    Blynk.begin(auth);
    tim_blynk = millis();
    DEBUG("Blynk Init Done ...");
}

void run_blynk()
{
    Blynk.run();
}

Serial monitor output

[    1200] Getting IP...
[8458] IP:192.168.1.122
[8458] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.7 on Arduino Uno

[8576] Connecting to blynk-cloud.com:80
[40833] Connecting to blynk-cloud.com:80
[73039] Connecting to blynk-cloud.com:80
[105247] Connecting to blynk-cloud.com:80
[137454] Connecting to blynk-cloud.com:80
[169661] Connecting to blynk-cloud.com:80
[201869] Connecting to blynk-cloud.com:80
[202169] Ready (ping: 115ms).

The latest version of blynk legacy library is 0.6.1, so 0.6.7 seems very odd to me.

1 Like

I have updated the library to latest version but the situation is the same.

here is the debug info

[1200] Getting IP...
[8458] IP:192.168.1.113
[8458]
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.0.1 on Arduino Uno

[8576] Connecting to blynk-cloud.com:80
[40825] Connecting to blynk-cloud.com:80
[73032] Connecting to blynk-cloud.com:80
[105239] Connecting to blynk-cloud.com:80
[137447] Connecting to blynk-cloud.com:80
[169654] Connecting to blynk-cloud.com:80
[201862] Connecting to blynk-cloud.com:80
[202161] Ready (ping: 117ms).

I am using platformio here are library versions that are available there .

As @John93 has said, version 0.6.1 is the best version to use with Legacy.

Personally, I’d suggest trying one of the Sketch Builder examples and see what results that gives.

Pete.

Now I am testing with Arduino IDE

@PeteKnight Library version now is 0.6.1 but the result is the same.

Example from blynk library

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Social networks:            http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  This example shows how to use Arduino Ethernet Shield 2 (W5500)
  to connect your project to Blynk.

  Note: This requires Ethernet2 library
    from http://librarymanager/all#Ethernet2

        Pins 10, 11, 12 and 13 are reserved for Ethernet module.
        DON'T use them in your sketch directly!

  Feel free to apply it to any other example. It's simple!
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <SPI.h>
#include <Ethernet2.h>
#include <BlynkSimpleEthernet2.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "auth";


void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth);
  // You can also specify server:
  //Blynk.begin(auth, "blynk-cloud.com", 80);
  //Blynk.begin(auth, IPAddress(192,168,1,100), 8080);
  // For more options, see Boards_Ethernet/Arduino_Ethernet_Manual example
}

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

Serial monitor output

14:57:21.388 -> [0] Getting IP...
14:57:23.625 -> [2247] IP:192.168.1.113
14:57:23.625 -> [2248] 
14:57:23.671 ->     ___  __          __
14:57:23.671 ->    / _ )/ /_ _____  / /__
14:57:23.718 ->   / _  / / // / _ \/  '_/
14:57:23.718 ->  /____/_/\_, /_//_/_/\_\
14:57:23.765 ->         /___/ v0.6.1 on Arduino Uno
14:57:23.812 -> 
14:57:23.812 -> [2366] Connecting to blynk-cloud.com:80
14:57:56.005 -> [34614] Connecting to blynk-cloud.com:80
14:58:28.184 -> [66822] Connecting to blynk-cloud.com:80
14:59:00.402 -> [99028] Connecting to blynk-cloud.com:80
14:59:32.586 -> [131236] Connecting to blynk-cloud.com:80
15:00:04.805 -> [163443] Connecting to blynk-cloud.com:80
15:00:37.022 -> [195651] Connecting to blynk-cloud.com:80
15:00:37.304 -> [195942] Ready (ping: 113ms).

Have you tried restarting your router and any Ethernet switches between your Uno and the router?

If that doesn’t help, try using the Ethernet Manual example where you specify the MAC, IP address, gateway, DNS etc for your network.

Pete.