Get Mac address of client connected with esp8266

最后都变了- 提交于 2019-12-23 17:50:19

问题


I turned my esp8266 as an access point, so that the mobile devices could connect to it. Want to get the macAddress of the devices connected to it. How could I get it?


回答1:


I got the answer from here

and it works

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



回答2:


If i use the code this error comes up:

error: invalid conversion from 'ip4_addr*' to 'ip_addr*' [-fpermissive]
IPaddress = &stat_info->ip;

I resolved it with, due to invalid type conversion:

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

The change of the core ESP8266 IPAdress.h from Adrian McEwen could also fix this issue.



来源:https://stackoverflow.com/questions/42593385/get-mac-address-of-client-connected-with-esp8266

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!