Skip to main content
edited body
Source Link

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);     
}

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 15 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);     
}

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 20 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);     
}
added 140 characters in body
Source Link

#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; const int output_reset = 4; 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#include (WiFi<ESP8266WiFi.softAPgetStationNumh>

//WIFI Access point setup
const char* Ssid = "SSID";
const char* Password = "Password";
IPAddress ip(10,0,0,10)==0;
IPAddress gateway(10,0,0,1);
IPAddress subnet(255,255,255,0);
WiFiServer server(80);                    //loop here whileSet noweb APserver isport connectednumber to this
80


// stationGPIO pins
const int output_set = 5;
int delay_loop=0;

void setup() 
{
  // Data delayDirection
  pinMode(1output_set, OUTPUT); 

  // Output delay_loop++;initial Values
  digitalWrite(output_set, LOW);

 if WiFi.softAPConfig(delay_loop>=20000ip,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.softAPgetStationNum()==0)    {
        digitalWrite(output_reset, HIGH);
 //loop here while no AP is connected to this station
{
    delay(1001);
    delay_loop++;
    digitalWrite(output_reset,if LOW(delay_loop>=20000);
        delay(100);                  
    {
        delay_loop=0; 
        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);     
}

}

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

#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; const int output_reset = 4; 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.softAPgetStationNum()==0)              //loop here while no AP is connected to this station
{
    delay(1);
    delay_loop++;
    if (delay_loop>=20000)                          
    {
        digitalWrite(output_reset, HIGH);
        delay(100);
        digitalWrite(output_reset, LOW);
        delay(100);
        delay_loop=0; 
        ESP.deepSleep(60e6);                          //go to sleep for 60 sec -wake pin externally connected to reset pin
    } 
}

}

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

#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 15 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);     
}
Source Link

ESP8266 in AP Mode -determining if a station is connected

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; const int output_reset = 4; 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.softAPgetStationNum()==0)              //loop here while no AP is connected to this station
{
    delay(1);
    delay_loop++;
    if (delay_loop>=20000)                          
    {
        digitalWrite(output_reset, HIGH);
        delay(100);
        digitalWrite(output_reset, LOW);
        delay(100);
        delay_loop=0; 
        ESP.deepSleep(60e6);                          //go to sleep for 60 sec -wake pin externally connected to reset pin
    } 
}

}

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