Chat freely about anything...
User avatar
By frjariello
#74507 Hi,
I made a small script to check when someone (smartphone) connects to my Esp in order to enable a command.
The problem is that when the smartphone goes away and loses the connection wifi_softap_get_station_num is not updated and still counts it as connected...

Is there any way to force an update?

Or at worst, is it possible to set a connection duration, so that after 2 minutes it disconnects the client?

Thanks

bye bye
User avatar
By frjariello
#74788 my use is very simple, this is the code, which I partly took from a post on this forum
Code: Select all#include <ESP8266WiFi.h>

extern "C" {
#include<user_interface.h>
}

const char *ssid = "ssidWiFi";
const char *password = "password";

boolean Richiesta = false;
unsigned char connessioni = 0;

int D0 = 2;
int D4 = 16;

void setup() {
  pinMode(D4, OUTPUT);
  pinMode(D0, OUTPUT);
  Serial.begin(115200);
 
  system_phy_set_max_tpw(50);
 
  WiFi.softAP(ssid, password);
  WiFi.begin();
  Serial.println("");
  Serial.println("- - - WiFi Avviato - - -");
  delay(1000);
}

void loop() {
 
  client_status();
  delay(1000);
  }

void client_status() {

    unsigned char number_client;
    struct station_info *stat_info;
    struct ip_addr *IPaddress;
    IPAddress address;
   
    number_client= wifi_softap_get_station_num();

    stat_info = wifi_softap_get_station_info();

    if (stat_info != NULL ) {
      IPaddress = &stat_info->ip;
      address = IPaddress->addr;
    }
   
    if (connessioni < number_client) {
      Serial.println(millis()/1000);
      Serial.print(" Numero di connessioni = ");
      Serial.println(number_client);
      connessioni = number_client;
      Richiesta = true;
    }
   
    if (stat_info != NULL && Richiesta) {
   
      IPaddress = &stat_info->ip;
      address = IPaddress->addr;
     
      Serial.println(millis()/1000);
      Serial.print("- Indirizzo IP assegnato = ");
      Serial.println((address));
      Serial.print("- MAC Address = ");
      Serial.print(stat_info->bssid[0],HEX);
      Serial.print(stat_info->bssid[1],HEX);
      Serial.print(stat_info->bssid[2],HEX);
      Serial.print(stat_info->bssid[3],HEX);
      Serial.print(stat_info->bssid[4],HEX);
      Serial.print(stat_info->bssid[5],HEX);
      Serial.println();
     
      digitalWrite(D4, 1);
      Serial.println("- Led ACCESO");
      digitalWrite(D0, 1);
      Serial.println("- Comando ad ON");
      Serial.println();
 
      delay(1000);
 
      digitalWrite(D4, 0);
      Serial.println("- Led SPENTO");
      digitalWrite(D0, 0);
      Serial.println("- Comando ad OFF");
      Serial.println();
      Richiesta = false;

    }

    else {
     
      if (number_client == 0) {
        Serial.println(millis()/1000);
        Serial.println("- Nessuna Connessione");
        digitalWrite(D4, 0);
        Serial.println("- Led SPENTO");
        digitalWrite(D0, 0);
        Serial.println("- Comando ad OFF");
        Serial.println();
        connessioni = 0;
      }
     
    }

}


But once connected, if I move away and the connection falls, the number of wifi_softap_get_station_num() does not change :(

bye bye