Arduino ESP32, WiFi.status returns 3 (WL_Connected) only can't ping the ipadress

I’ve connected an ESP32 to my home network. While nearby the wifi point i get an good connection. When i move away from the wifi point the connected is getting worse witch makes sense cause of the range. Only wifi status returns code 3 witch means WL_connected. Only while pinging or sending TCP message towards the ESP32 i don’t receive anything in return. Any ideas why i don’t receive a message back?

I understand that range can and will be a problem, only can’t link why the ESP32 says connected and i can’t get a reaction. Any reasons or explanation on that would be helpful.

 #include <WiFi.h>

WiFiServer wifiServer(80);
String Wifi_read;

// Wifi settings
const char *ssid = "ssid";
const char *password = "password";
IPAddress local_IP(10,0,0,93);
IPAddress gateway(10,0,0,138);
IPAddress subnet(255,255,255,0);
int Wifi_led = 2;
int Wifi_status;

// given data
const int ADC_resolution = 4095;
const float VCC = 3.3;

//Settings
int Average_readings = 299; // Starting at 0

//Timers
unsigned long currenttime;
unsigned long nexttime = 0;
int interval = 50;
unsigned long Wifi_nexttime = 0;
int Wifi_interval = 125;
unsigned long check_wifi = 10000;


// NTC_1 variables
int NTC_1 = 34;
const int Resistor_1 = 9986;
float ADC_value_1;
float Voltage_1;
float NTC_R_raw_1;
float NTC_R_avg_1;
float NTC_array_1[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};
int Array_2 = 0;
float T02;
int T02_low;
int T02_high;
float Delta_t;

// values voor lookup table
float value[] = 
{32869, 31229, 29680, 28217, 26834, 25527, 24291, 23122, 22015, 20968,  // 0 t/m 9 degree
19977, 19038, 18149, 17306, 16507, 15750, 15032, 14350, 13703, 13090,   // 10 t/m 19 degree
12507, 11953, 11427, 10927, 10452, 10000, 9570, 9161, 8772, 8402,       // 20 t/m 29 degree
8049, 7713, 7393, 7088, 6798, 6521, 6256, 6004, 5764, 5534,             // 30 t/m 39 degree
5315, 5106, 4906, 4715, 4533, 4358, 4191, 4032, 3879, 3733,             // 40 t/m 49 degree
3594, 3460, 3332, 3210, 3092, 2980, 2872, 2768, 2669, 2574,             // 50 t/m 59 degree
2483, 2396, 2312, 2231, 2154, 2080, 2009, 1940, 1874, 1811,             // 60 t/m 69 degree
1750, 1692, 1636, 1582, 1530, 1480, 1431, 1385, 1340, 1298,             // 70 t/m 79 degree
1256, 1216, 1178, 1141, 1105, 1071, 1038, 1006, 975, 945,               // 80 t/m 89 degree
916, 889, 862, 836, 811, 787, 764, 741, 720, 699,                       // 80 t/m 89 degree
678, 659, 640, 622, 604, 587, 570, 554, 539, 524,                       // 90 t/m 99 degree
509, 495, 481, 468, 455, 443, 431, 419, 408, 397,                       // 100 t/m 109 degree
386, 376, 366, 357, 347, 338};                                           // 110 t/m 115 degree

int value_number;



void setup() { 
  Serial.begin(115200);
  pinMode(Wifi_led, OUTPUT);

  if (!WiFi.config(local_IP, gateway, subnet))  
  { Serial.println("STA Failed to configure");  }
  
  WiFi.begin(ssid, password);
  wifiServer.begin();
  Serial.println(WiFi.localIP());
}

void loop() {
WiFiClient client = wifiServer.available();
currenttime = millis();
Wifi_indication();
Wifi_labview();

if (currenttime >= nexttime)  {
  nexttime += interval;
  Temps();
}
}

void Temps() {
  Temps_T01();
  Wifi_labview();
  Temps_T02();
  Wifi_labview();
  Temps_Delta_t();
  Wifi_labview();
}

void Temps_T01()  {
// T01
  // Reading the analog value
  ADC_value_1 = analogRead(NTC_1); // Reading the ADC value
  Voltage_1 = (ADC_value_1 * VCC) / ADC_resolution;
  NTC_R_raw_1 = Resistor_1 / (VCC - Voltage_1) * Voltage_1;

  // Smoothing the resistance value 
  NTC_array_1[Array_1] = NTC_R_raw_1;
  Array_1 += 1;
  if (Array_1 > Average_readings) {Array_1 = 0;}
  NTC_R_avg_1 = 0;
  for (int i = 0; i < Average_readings;)  {
    NTC_R_avg_1 += NTC_array_1[i];
    i++;
  }
  NTC_R_avg_1 = NTC_R_avg_1 / Average_readings;
  if (NTC_array_1[Average_readings] == 0 or NTC_R_raw_1 <= 500) { NTC_R_avg_1 = 0; }
  
  // making an temperatur with decimals 
  value_number = 0;
  while (value[value_number] >= NTC_R_avg_1) {
    T01_low = value_number;
    value_number++;
  }
  T01_high = value_number;
  T01 = T01_low + (1 - ((T01_high - T01_low) / (value[T01_low] - value[T01_high]) * (NTC_R_avg_1 - value[T01_high])));
}

void Temps_T02()  {
// T02
  // Reading the analog value
  ADC_value_2 = analogRead(NTC_2); // Reading the ADC value
  Voltage_2 = (ADC_value_2 * VCC) / ADC_resolution;
  NTC_R_raw_2 = Resistor_2 / (VCC - Voltage_2) * Voltage_2;

  // Smoothing the resistance value 
  NTC_array_2[Array_2] = NTC_R_raw_2;
  Array_2 += 1;
  NTC_R_avg_2 = 0;
  if (Array_2 > Average_readings) {Array_2 = 0;}
  for (int i = 0; i < Average_readings;)  {
    NTC_R_avg_2 += NTC_array_2[i];
    i++;
  }
  NTC_R_avg_2 = NTC_R_avg_2 / Average_readings;
  if (NTC_array_2[Average_readings] == 0 or NTC_R_raw_2 <= 500) { NTC_R_avg_2 = 0; }
  
  // making an temperatur with decimals 
  value_number = 0;
  while (value[value_number] >= NTC_R_avg_2) {
    T02_low = value_number;
    value_number++;
  }
  T02_high = value_number;
  T02 = T02_low + (1 - ((T02_high - T02_low) / (value[T02_low] - value[T02_high]) * (NTC_R_avg_2 - value[T02_high])));
}

void Temps_Delta_t()  {
//Delta T
  Delta_t = T01 - T02;
}

void Wifi_indication() {
  Serial.println(WiFi.status());
  if (WiFi.status() != WL_CONNECTED) {
    if (currenttime >= Wifi_nexttime)  {
      Wifi_nexttime += Wifi_interval;
      if (Wifi_status == HIGH) 
      { Wifi_status = LOW;  }
      else  
      { Wifi_status = HIGH; }
      delay(100);
    }

     if (currenttime > check_wifi)  {
      WiFi.disconnect();
      WiFi.begin(ssid, password);
      check_wifi = currenttime + 30000;
      Serial.println("Restarting wifi connection");
    }
    
   }
   else  
   {  Wifi_status = HIGH; }
   digitalWrite(Wifi_led, Wifi_status);

  
}

void Wifi_labview() {
WiFiClient client = wifiServer.available();
  if (client.available()) {
    while (client.available() > 0)  {
      char a = client.read();
      Wifi_read += a;
      Serial.println(Wifi_read);
    }
  }

  if (Wifi_read == "Read")  {
    client.print("T01: ");
    client.print(T01);
    client.print("\t");
    client.print("T02: ");
    client.print(T02);
    client.print("\t");
    client.print("DeltaT: ");
    client.println(Delta_t);   
  }

  Wifi_read = "";
}