So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By clayton
#74698 Hi,

I have configured the esp8266 as an AP using softAP. I would like to turn on the WIFI radio for a period of time, and if no connections are made within that time, I want to go to sleep for another period of time. This is to conserve battery power if no stations are connected.

I am having trouble determining if a station is connected to my wifi AP. My code is below (i have simplified the code greatly- and just kept the problem domain). I get "wfii_softap_get_station_num not declared in this scope". How can I get this code to work?

#include <ESP8266WiFi.h>

//WIFI Access point setup
const char* Ssid = "SSID";
const char* Password = "SSID!!";
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;
const int output_reset = 4;
char number_of_clients=0;
int delay_loop=0;

void setup()
{
// Data Direction
pinMode(output_set, OUTPUT);
pinMode(output_reset, OUTPUT);


// Output initial Values
digitalWrite(output_set, LOW);
digitalWrite(output_reset, 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 15 sec timeframe, go to sleep.

while (wifi_softap_get_station_num()==0) //loop here while no AP is connected to this station
{
delay(1);
delay_loop++;
if (delay_loop>=15000)
{
ESP.deepSleep(20e6); //go to sleep for 20 sec -wake pin externally connected to reset pin
}
}

}



void loop()
{
digitalWrite(output_set, HIGH);
delay(200);
digitalWrite(output_set, LOW);
delay(400);
}