ESP8266 doesn't recognise / detect disconnection of station???

Hi,
I connected two ESP8266s via WiFi - one being a soft Access Point, and the second one being a Station.
When I disconnect power from the Station ESP8266, the AP seems not to recognise the disconnection. Why? How can I make the AP recognise the STA as being disconnected when its power is down?

I also connected my computer and phone to the AP (which increases the number of STA detected), and when I disconnect them, the disconnection is detected by the AP and the number of the connection printed to the Serial Monitor decreases immediately. But when I simply unplug the power supply from the STA ESP8266, and even there’s nothing connected to AP anymore - it still prints “Stations connected = 1”. Below are my codes.

Soft AP’s Code:

#include <ESP8266WiFi.h>

void setup()
{
  Serial.begin(115200);
  Serial.println();

  Serial.print("Setting soft-AP ... ");
  boolean result = WiFi.softAP("ESPsoftAP_01");

  if(result == true)
  {
    Serial.println("Ready");
  }
  else
  {
    Serial.println("Failed!");
  }
}

void loop()
{
  Serial.printf("Stations connected = %d\n", WiFi.softAPgetStationNum());
  delay(3000);
}

Station’s Code:

#include <ESP8266WiFi.h>

void setup()
{
  Serial.begin(115200);
//  Serial.setDebugOutput(true);
  Serial.println();
  WiFi.begin("ESPsoftAP_01");
  Serial.print("Connecting");
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println();

  Serial.print("Connected, IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {}

it will. give it time. it is how TCP works.

there is difference between disconnect and power off. try to remove the battery from the phone, while it is connected

Juraj:
it will. give it time. it is how TCP works.

there is difference between disconnect and power off. try to remove the battery from the phone, while it is connected

Hi Juraj, thank you again for your help.
Hmmm - I actually don't know much about TCP or protocols in general. When you say how TCP works, do you mean by they are not very fast/responsive?

Ok so I tried it again. I literally waited for minutes, after I unplugged the power of the STA ESP8266. But it still prints "Stations connected = 1", when it should be 0...

I also tried again with my phone, this time powering down the phone itself instead of just 'disconnecting' the wifi. Again, as soon as the phone turned off, the serial monitor printed "Stations connected = 0".

Why is AP so responsive to my phone but not the Station ESP8266??? Is this because the phone is using some other sort of protocol that is not TCP??????
Is there any way that I can make the Station ESP8266 as responsive as my phone???

cloudurchin:
Hi Juraj, thank you again for your help.
Hmmm - I actually don't know much about TCP or protocols in general. When you say how TCP works, do you mean by they are not very fast/responsive?

Ok so I tried it again. I literally waited for minutes, after I unplugged the power of the STA ESP8266. But it still prints "Stations connected = 1", when it should be 0...

I also tried again with my phone, this time powering down the phone itself instead of just 'disconnecting' the wifi. Again, as soon as the phone turned off, the serial monitor printed "Stations connected = 0".

Why is AP so responsive to my phone but not the Station ESP8266??? Is this because the phone is using some other sort of protocol that is not TCP??????
Is there any way that I can make the Station ESP8266 as responsive as my phone???

powering down the phone disconnects connections. remove the battery suddenly.

stations connected is something else as clients. that is not TCP

Juraj:
powering down the phone disconnects connections. remove the battery suddenly.

stations connected is something else as clients. that is not TCP

Ooh okay - hmm I’m not able to remove the battery from my phone because my phone doesn’t allow easy access to the battery component. Anyhow, your point is - if I was to remove the battery from my phone, it will behave the same way to the STA ESP8266 and not be detected by the AP ESP8266 as being disconnected - am I right?

I got that, but then how can I make the AP detect that the STA ESP8266 is ‘powered down’ and no longer existing in the network, as soon as the STA powers down? Is it even possible to do that?

Sorry, I don't know how a WiFi AP handles stations.

Juraj:
Sorry, I don't know how a WiFi AP handles stations.

That's okay, thank you for your help though!

I've been reading on ESP8266 forums too and... it might to do with a 'ping'??? Some sort of method to check the availability of the Station continuously, though I'm still unsure what it is/how it could be achieved.

I'll keep googling, but any further suggestion or help would be super welcome,