Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By FRANCISCOGIMENO1000
#80924 Hello, I have a problem with this function, when asked
tells you how many clients are connected.
The problem is that it gives a value greater than zero for a few seconds, if someone tries to connect even with the wrong Wi-Fi password.

There is some way of knowing how many real connected clients (which the key of the wifi they have set is correct and are really connected).

Thanks and best regards
Last edited by FRANCISCOGIMENO1000 on Thu Mar 07, 2019 1:07 pm, edited 1 time in total.
User avatar
By RichardS
#80931 I am not an expert on this topic, but I would assume you see them connected for a bit for it to determine they have timed out so it can take the timeout period, and even if wrong password, they need to timeout... seems like its probably working as it should.... as it only allocated so much memory to deal with clients and this count goes against it.

Now how to determine how many are real people logged in.... no clue. sorry.

RichardS
User avatar
By FRANCISCOGIMENO1000
#80935 Thanks for your help.



Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

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

/* configuration  wifi */
const char *ssid = "COblaster";

ESP8266WebServer server(80);

void handleRoot() {
  server.send(200, "text/html", "<h1>You are connected</h1>");
  String addy = server.client().remoteIP().toString();
  Serial.println(addy);
}

void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");
  WiFi.softAP(ssid);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.begin();
  Serial.println("HTTP server started"); 
}

void loop() {
  server.handleClient();   
  delay(5000);
  client_status();
  delay(4000);
}

void client_status() {

unsigned char number_client;
struct station_info *stat_info;

struct ip_addr *IPaddress;
IPAddress address;
int i=1;

number_client= wifi_softap_get_station_num();
stat_info = wifi_softap_get_station_info();

Serial.print(" Total connected_client are = ");
Serial.println(number_client);

while (stat_info != NULL) {

IPaddress = &stat_info->ip;
address = IPaddress->addr;

Serial.print("client= ");

Serial.print(i);
Serial.print(" ip adress is = ");
Serial.print((address));
Serial.print(" with mac adress is = ");

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

stat_info = STAILQ_NEXT(stat_info, next);
i++;
Serial.println();

}
delay(500);
}




I tried to try this code to know the ip of the connected clients, but I get this error:

error: invalid conversion from 'ip4_addr*' to 'ip_addr*' [-fpermissive]
IPaddress = &stat_info->ip;
User avatar
By FRANCISCOGIMENO1000
#80942 Well friends, I have it solved, I do not know if it is the best way but it works.
I also have to say that the information there is not clear.

I leave it in case someone can use it:

Code: Select all
// include plain C library
extern "C" {
#include "user_interface.h"
}

boolean clientewifisi=0; //global var



void clientesreales()
{
struct station_info *station_list = wifi_softap_get_station_info();
boolean haywifi = 0;

while (station_list != NULL)
{
clientewifisi = 1;
haywifi = 1;
station_list = STAILQ_NEXT(station_list, next);
}

if (haywifi == 0)
{
clientewifisi = 0;
}

}



Basically if it enters

while (station_list! = NULL)
{
.....
}

is that there are wifi clients authenticated.
This function gives client data such as ip, mac ect.
These data do not interest me, so I do not look at them.

If it does not enter there are no real client wifi.

That is all
Greetings and thanks to all.