I have an ESP8266 running in AP mode using softAP and i want to conserve battery life. I am wanting to turn on wifi and advertise SSID for 20 seconds. If no station connects to the ssid within the 20 seconds, I want to go to sleep for 1 minute, otherwise I do not sleep.
My problem is that I cannot get "WiFi.softAPgetStationNum()" working. when I build i get a message that this is not part of ESP8266WiFi class. I have attached simplified code.
Can someone help me to achieve this please?
#include <ESP8266WiFi.h>
//WIFI Access point setup
const char* Ssid = "SSID";
const char* Password = "Password";
IPAddress ip(10,0,0,10);
IPAddress gateway(10,0,0,1);
IPAddress subnet(255,255,255,0);
WiFiServer server(80); // Set web server port number to
80
// GPIO pins
const int output_set = 5;
int delay_loop=0;
void setup()
{
// Data Direction
pinMode(output_set, OUTPUT);
// Output initial Values
digitalWrite(output_set, LOW);
WiFi.softAPConfig(ip,gateway,subnet);
WiFi.softAP(Ssid,Password);
server.begin();
// check to see if a station is connected to this AP. If no station
connected within 1520 sec timeframe, go to sleep.
while (WiFi.softAPgetStationNum()==0) //loop here while no AP is connected to this station
{
delay(1);
delay_loop++;
if (delay_loop>=20000)
{
ESP.deepSleep(60e6); //go to sleep for 60 sec -wake pin externally connected to reset pin
}
}
}
void loop()
{
digitalWrite(output_set, HIGH); //Flash led once station is connected
delay(200);
digitalWrite(output_set, LOW);
delay(400);
}