-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Getting IP address of device connected to SoftAP #2100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This will not work. |
so how to get the IP address as soon as received any connection to my AP ESP module ?, I intend register each device information as it connected another question |
Short answer, you can't (with the current version). Currently event handlers registered via |
how about the MAC address? , I've noticed when I enable |
As I said, currently you can't get information about clients connected to WiFi using Arduino APIs. You can also get client's IP address as soon as the client connects to HTTP server. Esp8266WebServer library does not handle concurrent connections. You may want to check me-no-dev's asynchronous http server library if you need to handle multiple clients concurrently. |
not very concurrently. actually I have plan to set one ESP as AP and others(5 to 10 ) as Stations , which are periodically send data to the AP module , I don't know what strategy should follow ? do you think your Esp8266WebServer can handle such a Server -Clients net |
@mkeyno I have the same plan right now and I am thinking about a solution too. Without a MAC or IP of the clients, there is currently no chance to implement a reliable solution. looking forward :) |
ESP8266: Simple Ping, is that a solution for your problem? Visit my website: Modify/add in the download (IP and names as example): |
thanks @onkie although I couldn't find any code form your page or the links you provided, however I was wondering what would be your approach to get IP of connected devices? is it in setup or loop function or tied to wifievent handler ? |
I am not on Github but i have my own website. |
Please note! |
Can you please tell me when event data will be available? |
Hello. #include <ESP8266WiFi.h> #include "ESP8266WiFiGeneric.h" extern "C" { int NeedRefresh=0; /* Set these to your desired credentials. */ ESP8266WebServer server(80); bool MomaDHCPInfoReady() softap_stations_cnt = wifi_softap_get_station_num(); // Count of stations which are connected to ESP8266 soft-AP void showinfo() softap_stations_cnt = wifi_softap_get_station_num(); // Count of stations which are connected to ESP8266 soft-AP void handleRoot() { You are connected at "+s+"");} void WiFiEvent(WiFiEvent_t event) { struct station_info *stat_info;
/*
/* void setup() {
} |
Hello . i used Arduino for program. void setup() { and used this function: void WiFiEvent(WiFiEvent_t event) { and used this variabel in global section: int NeedRefresh=0; and in Loop() function: void loop() { and used this: void showinfo() softap_stations_cnt = wifi_softap_get_station_num(); // Count of stations which are connected to ESP8266 soft-AP and used this: bool MomaDHCPInfoReady() softap_stations_cnt = wifi_softap_get_station_num(); // Count of stations which are connected to ESP8266 soft-AP .... |
Hello! #include <ESP8266WiFi.h>
// include plain C library
extern "C" {
#include "user_interface.h"
}
#define YOUR_WIFI_SSID "******-******"
#define YOUR_WIFI_PASSWD "******-******"
boolean waitingDHCP=false;
char last_mac[18];
// Manage incoming device connection on ESP access point
void onNewStation(WiFiEventSoftAPModeStationConnected sta_info) {
Serial.println("New Station :");
sprintf(last_mac,"%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(sta_info.mac));
Serial.printf("MAC address : %s\n",last_mac);
Serial.printf("Id : %d\n", sta_info.aid);
waitingDHCP=true;
}
void setup() {
static WiFiEventHandler e1;
Serial.begin(115200);
Serial.println();
WiFi.mode(WIFI_AP_STA);
WiFi.begin(YOUR_WIFI_SSID, YOUR_WIFI_PASSWD);
// Event subscription
e1 = WiFi.onSoftAPModeStationConnected(onNewStation);
}
void loop() {
if (waitingDHCP) {
String cb;
if (deviceIP(last_mac,cb)) {
Serial.println("Ip address :");
Serial.println(cb); //do something
} else {
Serial.println("Problem during ip address request :");
Serial.println(cb); //do something else
}
}
delay(2000);
}
boolean deviceIP(char* mac_device, String &cb) {
struct station_info *station_list = wifi_softap_get_station_info();
while (station_list != NULL) {
char station_mac[18] = {0}; sprintf(station_mac, "%02X:%02X:%02X:%02X:%02X:%02X", MAC2STR(station_list->bssid));
String station_ip = IPAddress((&station_list->ip)->addr).toString();
if (strcmp(mac_device,station_mac)==0) {
waitingDHCP=false;
cb = station_ip;
return true;
}
station_list = STAILQ_NEXT(station_list, next);
}
wifi_softap_free_station_info();
cb = "DHCP not ready or bad MAC address";
return false;
} |
Closing as resolved. |
hi,
I'm trying to get IP address of each device that has been connected to AP mode ESP, I use the following code but the code just reveal any connection that been made or disconnected , it there any way that find device IP as soon as get any connection to AP ESP
`void WiFiEvent(WiFiEvent_t event) {
//Serial.printf("[WiFi-event] event: %d\n", event);
{
case WIFI_EVENT_STAMODE_CONNECTED:
Serial.println("[ST]WiFi just connected"); break;
case WIFI_EVENT_STAMODE_DISCONNECTED:
Serial.println("[ST]WiFi lost connection"); break;
case WIFI_EVENT_STAMODE_AUTHMODE_CHANGE:
Serial.println("[ST]WiFi mode changed"); break;
case WIFI_EVENT_STAMODE_GOT_IP:
Serial.print("[ST]WiFi connected, IP=");Serial.println(WiFi.localIP()); break;
case WIFI_EVENT_STAMODE_DHCP_TIMEOUT:
Serial.println("[ST]WiFi DHCP TIMEOUT"); break;
case WIFI_EVENT_SOFTAPMODE_STACONNECTED:
{
WiFiClient client = server.client();
Serial.print("[AP] new clinet, IP=");Serial.println(client.remoteIP());
}
break;
case WIFI_EVENT_SOFTAPMODE_STADISCONNECTED:
Serial.println("[AP]client disconnected"); break;
case WIFI_EVENT_SOFTAPMODE_PROBEREQRECVED:
Serial.println("[AP]err on recieved request"); break;
}
}`
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: