Connnection with high ping after connection failed

Hello Dear community
Arduino Atmega2560
ethernet lan (ENC28J60) for ethernet connection
2 x dht 11 sensor
1x anenometre for windspeed

ı have a project also ı have no problem in my home but
when ı go to my office ı cant connect to blynk.cloud ı have two problems outside
issue is —> seeing like this {{ [504712] Connecting to blynk-cloud.com: 0 }}
İf the port 80 like this [504712] Connecting to blynk-cloud.com: 80 ı can connect but with high ping between (250-600 ms ) after try to reconnect but when try to reconnect port ‘’ 0 ‘’ not : 80 port thus ı cant connect blynk server.
in my home everything be okay but office not be okay

in my opinion about ----- > bad internet connection but how can ı sure there is ethernet good or bad
also my serial monitor:

18:34:42.999 -> [0] Getting IP...
18:34:48.256 -> [5254] IP:192.168.1.29
18:34:48.256 -> [5255] 
18:34:48.256 ->     ___  __          __
18:34:48.256 ->    / _ )/ /_ _____  / /__
18:34:48.256 ->   / _  / / // / _ \/  '_/
18:34:48.290 ->  /____/_/\_, /_//_/_/\_\
18:34:48.290 ->         /___/ v1.1.0 on Arduino Mega
18:34:48.290 -> 
18:34:48.290 ->  #StandWithUkraine    https://bit.ly/swua
18:34:48.290 -> 
18:34:48.290 -> 
18:34:48.290 -> [5269] Connecting to 46.101.217.214:80
18:34:53.295 -> [10269] Connecting to 46.101.217.214:80
18:34:53.936 -> [10904] Ready (ping: 458ms).
18:35:48.290 -> [23269] reconnecting to 46.101.217.214:80
**18:35:53.295 -> [24269] reconnecting to 46.101.217.214:0**
**18:36:53.295 -> [28269] reconnecting to 46.101.217.214:0**  ***// why port: 0 try to connect it sould be " 80 " but here " 0 "***

#define BLYNK_TEMPLATE_ID "TMPLuAw3TgVo"
#define BLYNK_DEVICE_NAME "ÇandırSera"
#define BLYNK_AUTH_TOKEN "-K7AsdvolcfksdwlRXOAa3pzv4a63obNH"


#define BLYNK_PRINT Serial
#include <DHT.h>
#include <UIPEthernet.h>
#include <Ethernet.h>
#include <BlynkSimpleUIPEthernet.h>

#include <avr/wdt.h>
char auth[] = BLYNK_AUTH_TOKEN;
#define O_Apin 22  //PİN
#define C_Apin 24  //CloseAir
#define sera_2_O_Apin 26  //v9 
#define sera_2_C_Apin 28  //v11
#define Eng0 30   //Motor_On/Off
#define vana1 32
#define vana2 34
#define vana3 36

#define DHTPIN 3
#define DHTPIN0 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
DHT dht0(DHTPIN0, DHTTYPE);

int sera1 = 9 ;
int sera2 = 8 ;
int setPoint_O_A;
int setPoint_C_A;
int A_M ;
int O_A ;
int C_A ;
int sensorpin = A0;
int deger ;
float hiz;
float r;
int sera2_acma;
int sera2_kapama;
int J;
int L;
int t1;
int t , s_2 ;
unsigned long eskiZaman;
unsigned long yeniZaman;
unsigned long a ;
unsigned long b ;
unsigned long c , er;
unsigned long d ;
unsigned long ru ;
unsigned long bu ;

BLYNK_WRITE(V5)  // OPT_O
{
  setPoint_O_A = param.asFloat();
  Serial.print("açma value is: ");
  Serial.println(setPoint_O_A);
}
BLYNK_WRITE(V9)  // sera_ac_v9
{
  sera2_acma = param.asInt();

  if (sera2_acma == HIGH) {
    digitalWrite(sera_2_O_Apin, HIGH);
  }
  else {
    digitalWrite(sera_2_O_Apin, LOW);
  }
}
BLYNK_WRITE(V11)  // sera_kapat_v11
{
  sera2_kapama = param.asInt();
  if (sera2_kapama == HIGH) {
    digitalWrite(sera_2_C_Apin, HIGH);
  }
  else {
    digitalWrite(sera_2_C_Apin, LOW);
  }
}
BLYNK_WRITE(V2)  // OPT_C
{
  setPoint_C_A = param.asFloat();
  Serial.print("kapalı value is: ");
  Serial.println(setPoint_C_A);
}

BLYNK_WRITE(V3)  // M-O_A
{
  O_A = param.asInt();

  if (O_A == HIGH) {
    digitalWrite(O_Apin, HIGH);
  }
  else {
    digitalWrite(O_Apin, LOW);
  }
}
BLYNK_WRITE(V4)  // M-O_A
{
  C_A = param.asInt();

  if (C_A == HIGH) {
    digitalWrite(C_Apin, HIGH);
  }
  else {
    digitalWrite(C_Apin, LOW);
  }
}

void veriGonder() {
  float h = dht.readHumidity();
   float t = dht.readTemperature();
  float h1 = dht0.readHumidity();
  float t1 = dht0.readTemperature();
  deger = analogRead(sensorpin);
   Blynk.virtualWrite(V0, t); //sera1_sıcaklık
  Blynk.virtualWrite(V1, h); //nem
  Blynk.virtualWrite(V8, hiz); //rüzgar
  Blynk.virtualWrite(V12, t1); //sera2_sıcaklık
  Blynk.virtualWrite(V13, h1); //sera2_nem
  r = map(abs(sensorpin), 0, 410, 0.0, 70.0);
  hiz = (float)deger / 5.85;
}
void konumGonder() {
  if (J == HIGH) {
    Blynk.virtualWrite(V22, HIGH);
    Blynk.virtualWrite(V20, LOW);
  }
  else {
    Blynk.logEvent("havalandrma_konumu");
    Blynk.virtualWrite(V20, HIGH);
    Blynk.virtualWrite(V22, LOW);
  }
  if (L == HIGH) {
    Blynk.logEvent("havalandirma_konum");
    Blynk.virtualWrite(V32, HIGH);
    Blynk.virtualWrite(V30, LOW);
  }
  else {
    Blynk.logEvent("havalandrma_konumu");
    Blynk.virtualWrite(V30, HIGH);
    Blynk.virtualWrite(V32, LOW);
  }
}




BlynkTimer timer;
void setup() {
  timer.setInterval(500L, veriGonder);
  timer.setInterval(1000L, konumGonder);

  Serial.begin(115200);
  Blynk.begin(auth, "46.101.217.214", 80);
  dht.begin();
  dht0.begin();
  pinMode(sensorpin, INPUT);
  //pinMode(A0, INPUT_PULLUP);
  pinMode(O_Apin, OUTPUT);   //O_Apin
  pinMode(C_Apin, OUTPUT);  // C_Apin
  pinMode(sera_2_O_Apin, OUTPUT);   //O_Apin
  pinMode(sera_2_C_Apin, OUTPUT);  // C_Apin
  pinMode(Eng0,   OUTPUT);  // C_Apin
  pinMode(sera1, INPUT);  // C_Apin
  pinMode(sera2, INPUT);  // C_Apin

  digitalWrite(O_Apin, LOW);  //sera_1
  digitalWrite(C_Apin, LOW);
  digitalWrite(sera_2_O_Apin, LOW);  //sera_2
  digitalWrite(sera_2_C_Apin, LOW);
  Blynk.virtualWrite(V3, LOW);
  Blynk.virtualWrite(V4, LOW);
  Blynk.virtualWrite(V9, LOW);
  Blynk.virtualWrite(V11, LOW);
  er = 0 ;
  eskiZaman = 0 ;
  setPoint_O_A = 20;
  setPoint_C_A = 18;
  deger = 0 ;
  t = 19 ;
  t1 = 19 ;
}
void(* resetFunc) (void) = 0;

void loop()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float h1 = dht0.readHumidity();
  float t1 = dht0.readTemperature();
  Blynk.run();
  timer.run();

  
  if (Blynk.connected()) {
    Serial.println("blnyk conneck oldi ");
    Blynk.run();
    timer.run();
    float h = dht.readHumidity();
    float t = dht.readTemperature();
    float h1 = dht0.readHumidity();
    float t1 = dht0.readTemperature();
  }
  else {
    resetFunc();
    Serial.println("blnyk conneck EEEEELSEEEEEEE oldi ");
    myWatchDogEnable(0b100001); //8 seconds
    myWatchDogEnable(0b100001); //8 seconds
    myWatchDogEnable(0b100001); //8 seconds
    myWatchDogEnable(0b100001); //8 seconds
  }

  Blynk.run();
  timer.run();
  J =  digitalRead(sera1);
  L = digitalRead(sera2);

  if (hiz < 40) {
    er = millis();
    if (  isnan(t) ) {
      t = 19 ;  
    }
    else {
    }
    if ( isnan(t1) ) {
      t1 = 19 ;   
    }
    else {
    }
    if (setPoint_O_A <= t && setPoint_O_A <= t1)
    {
      Serial.print("ACMA--3");
      yeniZaman = millis();
      a = yeniZaman - eskiZaman;
      Serial.println("A-->");
      Serial.print(a);
      if ( a > 600000) {
        eskiZaman = yeniZaman;
        acma3();
      }
    }

    else if (setPoint_C_A >= t && setPoint_C_A >= t1)
    {
      Serial.print("kapama--3");

      yeniZaman = millis();
      b = yeniZaman - eskiZaman;
      if ( b > 600000)
      {
        eskiZaman = yeniZaman;
        kapama3();
      }
    }

    else if (setPoint_O_A <= t )
    {
      Serial.println("acma");
    
      yeniZaman = millis();
      a = yeniZaman - eskiZaman;
      if ( a > 600000) {
        eskiZaman = yeniZaman;
        acma();
      }
    }
    else if (setPoint_O_A <= t1 )
    {
      Serial.println("acma--2");
      Serial.print(t1);
      Serial.print("t ---<");
      Serial.println(t);
      yeniZaman = millis();
      a = yeniZaman - eskiZaman;
      if ( a > 600000) {
        eskiZaman = yeniZaman;
        acma2();
      }
    }


    else if (setPoint_C_A >= t)
    {
      Serial.println("kapama");
      Serial.print(t1);
      Serial.print("t ---<");
      Serial.println(t);
      yeniZaman = millis();
      b = yeniZaman - eskiZaman;
      if ( b > 600000)
      {
        eskiZaman = yeniZaman;
        kapama();
      }
    }

    else if (setPoint_C_A >= t1)
    {
      Serial.println("kapama--2");
      Serial.print(t1);
      Serial.print("t ---<");
      Serial.println(t);
      yeniZaman = millis();
      b = yeniZaman - eskiZaman;
      if ( b > 600000)
      {
        eskiZaman = yeniZaman;
        kapama2();
      }
    }
    else {
    }
  }
  else {
    Serial.println("halilibooo");
    if (J == LOW && L == LOW) {

      digitalWrite(O_Apin, LOW);  //sera_1
      digitalWrite(C_Apin, LOW);
      Blynk.virtualWrite(V3, LOW);
      Blynk.virtualWrite(V4, LOW);
      digitalWrite(sera_2_O_Apin, LOW);  //sera_2
      digitalWrite(sera_2_C_Apin, LOW);
      Blynk.virtualWrite(V9, LOW);
      Blynk.virtualWrite(V11, LOW);
    }
    else {

      yeniZaman = millis();
      bu = yeniZaman - er;
      if ( bu > 120000) {
        eskiZaman = yeniZaman;
        ruzgaar();
      }
    }
  }
}


void myWatchDogEnable(const byte interval) {
  Serial.println("reset fonkda suan");
  MCUSR = 0;
  WDTCSR |= 0b00011000;                             //set WDCE, WDE
  WDTCSR = 0b01000000 | interval;                   //set WDIE & delay
  wdt_reset();
}
ISR(WDT_vect) {
  Serial.println("reset iswr edt de");
  wdt_disable();
}

int ruzgaar() {
  yeniZaman = millis();
  eskiZaman = yeniZaman ;
  ru = yeniZaman - eskiZaman ;

  while ( ru < 100000 ) {
    Blynk.run();
    timer.run();
    yeniZaman = millis();
    ru = yeniZaman - eskiZaman;
    Serial.println("rüzgaar kesmesi");
    digitalWrite(O_Apin, LOW);
    digitalWrite(C_Apin, HIGH);
    Blynk.virtualWrite(V3, LOW);
    Blynk.virtualWrite(V4, HIGH);
    digitalWrite(sera_2_O_Apin, LOW);
    digitalWrite(sera_2_C_Apin, HIGH);
    Blynk.virtualWrite(V9, LOW);
    Blynk.virtualWrite(V11, HIGH);
  }

  Serial.print("rüzgaar - SERALAR KAPALI");
  digitalWrite(O_Apin, LOW);
  digitalWrite(C_Apin, LOW);
  Blynk.virtualWrite(V3, LOW);
  Blynk.virtualWrite(V4, LOW);
  digitalWrite(sera_2_O_Apin, LOW);
  digitalWrite(sera_2_C_Apin, LOW);
  Blynk.virtualWrite(V9, LOW);
  Blynk.virtualWrite(V11, LOW);
}
int acma3 () {

  yeniZaman = millis();
  c = yeniZaman - eskiZaman;

  while (c < 25000 ) {
    Blynk.run();
    timer.run();
    digitalWrite(O_Apin , HIGH);
    digitalWrite(sera_2_O_Apin, HIGH);
    yeniZaman = millis();
    c = yeniZaman - eskiZaman;
  }
  digitalWrite(O_Apin , LOW);
  digitalWrite(sera_2_O_Apin, LOW);
  eskiZaman = yeniZaman ;
}
int acma () {
  yeniZaman = millis();
  c = yeniZaman - eskiZaman;
  while (c < 25000 ) {
    Blynk.run();
    timer.run();
    digitalWrite(O_Apin , HIGH);
    yeniZaman = millis();
    c = yeniZaman - eskiZaman;
  }
  digitalWrite(O_Apin , LOW);
  eskiZaman = yeniZaman ;
}
int acma2 () {
  yeniZaman = millis();
  c = yeniZaman - eskiZaman;
  while (c < 25000 ) {
    Blynk.run();
    timer.run();
    digitalWrite(sera_2_O_Apin, HIGH);
    yeniZaman = millis();
    c = yeniZaman - eskiZaman;
  }
  digitalWrite(sera_2_O_Apin, LOW);
  eskiZaman = yeniZaman ;
}

int kapama () {
  yeniZaman = millis();
  d = yeniZaman - eskiZaman;
  while (d < 25000 ) {
    Blynk.run();
    timer.run();
    digitalWrite(C_Apin , HIGH);
    yeniZaman = millis();
    d = yeniZaman - eskiZaman;
  }
  digitalWrite(C_Apin , LOW);
  eskiZaman = yeniZaman ;
}
int kapama2 () {
  yeniZaman = millis();
  d = yeniZaman - eskiZaman;
  while (d < 25000 ) {
    Blynk.run();
    timer.run();
    digitalWrite(sera_2_C_Apin, HIGH);
    yeniZaman = millis();
    d = yeniZaman - eskiZaman;
  }
  digitalWrite(sera_2_C_Apin, LOW);
  eskiZaman = yeniZaman ;
}
int kapama3 () {
  yeniZaman = millis();
  d = yeniZaman - eskiZaman;
  while (d < 25000 ) {
    Blynk.run();
    timer.run();
    digitalWrite(C_Apin , HIGH);
    digitalWrite(sera_2_C_Apin, HIGH);
    yeniZaman = millis();
    d = yeniZaman - eskiZaman;
  }
  digitalWrite(C_Apin , LOW);
  digitalWrite(sera_2_C_Apin, LOW);
  eskiZaman = yeniZaman ;
}

Wow!
I think this is going to be the winner of the “Worst void loop() of the year awards - 2022” :trophy: :trophy: :trophy:

I’d bet that the reason your sketch is disconnecting in the first place is that void loop.
You should read this…

You already have a BlynkTimer set up, but you’re also doing millis() comparisons in your sketch too. Get rid of the millis stuff and user timers instead.

Also, you shouldn’t this:

instead, if you really feel the need to explicitly specify the server address you should use:

Blynk.begin(auth, "fra1.blynk.cloud", 80);

because the server IPs may change, but the regional subdomains won’t.

There are lots of other bits of your code that are a total mess. Just a couple of examples…

Blynk.virtualWrite’s in void setup very rarely work. If you wnat them to run once whne the device connects to the server you should put them in BLYNK_CONNECTED()

The first block of code declares four local variables and takes readings from your DHT11 sensors then executes Blynk.run() (which only achieves anything if Blynk.connected()==true).

The second block, which executes if Blynk.connected()==true, re-declares the same four local variables, takes more readings from your DHT11 sensors (overwriting the previous readings taken a fraction of a second ago) and once again executes Blynk.run().

Because DHT11 sensors don’t like to be read more than about once every 2 seconds (although I’d use 5 seconds to be on the safe side) none of these readings are likely to be useful.
In addition, your veriGonder function also re-declares these same variables as local to that function, and takes more DHT11 readings. This function is called once every half a second with a timer, compounding the problem with your void loop.

You need to take a serious look at your code structure and your variable scope before even starting to think about your ping and port 0- issue, as these may well be caused by the rest of your code.

Maybe you should start with the DHT example from the sketch builder and build-up your sketch in a logical way from there?

Pete.