WiFi.softAPgetStationNum() problems

HI All,
I have 2 ESP32 CAM AI thinkers working, one in AP mode and one in STA mode, both on same SSID. I can view both on individual IP addresses just fine.
On the AP board, I'm trying to flash the little red built-in LED GPIO33, when the STA one is connected.

void loop() {
    delay(500);
    uint8_t clientCount = WiFi.softAPgetStationNum();
    if (clientCount == 0) {
      LED_BLINKER = 0;                       // STOP LED blink
      digitalWrite(LED_BUILTIN, LOW);        // built-in LED ON (LED has pull-up)
    } else {
      LED_BLINKER = 1;                       // make LED blink
    }
    
    Serial.println(WiFi.softAPgetStationNum());

    // =======================================================
    // ALL GOOD ????      FLASH BUILT IN LED GPIO33 ???
    // =======================================================
    if (LED_BLINKER == 1) {                   // WiFi OK ?
      if (millis() - LED_Flasher >= 500) {
        digitalWrite(LED_BUILTIN, HIGH);      // built-in LED OFF (LED has pull-up)
      }
      if (millis() - LED_Flasher >= 1000) {
        digitalWrite(LED_BUILTIN, LOW);      // built-in LED ON   (LED has pull-up)
        LED_Flasher = millis(); 
      }
    } 
}

So, switch on the AP board and GPIO33 LED comes ON and WiFi.softAPgetStationNum() is 0 on the serial monitor.
Then switch on the STA board and when it connects, GPIO33 LED starts flashing ok and WiFi.softAPgetStationNum() shows as 1 on the serial monitor.
However, when I switch the STA board OFF, WiFi.softAPgetStationNum() stays as 1, doesn't go to 0. This leaves the LED still flashing !!!
Any ideas ???
Thank you
Trevor

Update -
Actually, WiFi.softAPgetStationNum() does eventually go to 0 and the LED stops flashing.
This takes about 3 minutes to happen ????

I'm not surprised. The AP has no way to know for sure when a station has disconnected. So it assumes that has happened if it gets no "heartbeat" signals from the station after a timeout period.

Thanks Paul,
Is there a way or another command to detect this in my code ?

You might try looking at the WiFi.h file to see if any public functions sound like they may help or if there is a public variable that can be interrogated.

An easy way to look at the WiFi.h is do a copile with no errors, then hilight WiFi and right click and select Go to Definition. You will see a RO tab open. Read away.

Here is what Google says


Actually, both AP and STA have timeouts, if wifi connection becomes inactive.
Maximilian Gerhardt explained everything and gives a solution, which works for me, by modifying the AP inactive timeout.
The default AP timeout is 300 seconds (5 minutes) .... soooooo long, which is why I couldn't make sense of what was happening. 10 seconds is the minimum and works fine for me.
The default STA timeout is 6 seconds, which did work ok, although I understand why until now.
I now have both boards flashing LEDs when all OK.
If the LEDs are ON (but not flashing) I know I have power OK, but then have Wifi problems.
Works great now.
See my post .... [WiFi.softAPgetStationNum() problems - #2 by maxgerhardt - espressif32 - PlatformIO Community]