First, you should initialize the GPIO of the LED more early in Setup, so it will be OFF even during the Wifi initialisation.
Second, your "devices = wifi_softap_get_station_num();" is located in Setup, so it won't be call more than once, therefore it will never reflect the real number of connections you wish to measure in the loop, you need to move it inside the loop itself, but be careful, maybe you want to measure only every second or half second.
Third, using delay() is not a good thing to do if you wish that your server continue to work, you have to share the CPU time across all tasks and use millis() to evaluate the 1 second blink rate.
Fourth, you "if"s are contradicting each other, it is like you wish a blink on both >=1 and <=1, that doesn't make sense.
Here is a snippet of untested code :
Code: Select allunsigned int prevMillis = 0;
boolean ledState = false;
void loop() {
if ((millis() - prevMillis) > 1000) { // 1000 millis = 1 second
prevMillis = millis();
devices = wifi_softap_get_station_num();
if (devices >= 1) {
if (!ledState)
digitalWrite(2, HIGH);
else
digitalWrite(2, LOW);
ledState = !ledState;
}
else {
digitalWrite(2, LOW);
ledState = false;
}
}
server.handleClient();
}