我可以在接入点模式(AP_MODE)下获得客户端mac-address,请参见下面的suGetClientMacAddress()
函数。可以在互联网上找到此代码。我尝试找出WiFi.mode(STA_MODE);
中客户端的MAC地址,但是找不到关于此的任何有用信息,不可能吗?当看起来不可能的时候,为什么不可能呢?还是还有一个“技巧”来使它起作用?
在下面可以找到AP_MODE
中的工作功能/版本
我使用的库是默认的ESP(v。2.4.0)库和Async Web / sockets库:
https://github.com/me-no-dev/ESPAsyncWebServer
#define SU_WCFG_SERVER_ASYNC
........
........
#ifdef SU_WCFG_SERVER_ASYNC
#define SUWebSocketServer AsyncWebSocket
#define SUWebServerRequest AsyncWebServerRequest
#else
......
#endif
extern "C" {
#include "user_interface.h" // Required for some low level wifi functions
}
............
............
String suIpAddressToString( IPAddress ipAddress )
{
return String( ipAddress[0] )+"."+
String( ipAddress[1] )+"."+
String( ipAddress[2] )+"."+
String( ipAddress[3] );
}
IPAddress suStringToIpAddress( String ipAddress )
{
IPAddress ip = IPAddress( 0, 0, 0, 0 );
char* pStr = (char*)ipAddress.c_str();
uint8_t i = strlen( pStr );
uint8_t iPos = 4;
// Test before start
if( i > 6 && pStr[i-1] != '.' )
{
while( i-- && iPos )
{
if( pStr[i] == '.' || i == 0 )
{
ip[--iPos] = String( (char*)&pStr[i+(i>0)] ).toInt();
pStr[i] = 0; // set null termination to truncate
}
}
}
return ip;
}
String suGetClientIp( SUWebServerRequest* request )
{
if( request )
{ return suIpAddressToString( IPAddress( request->client()->remoteIP() )); }
return "";
}
函数:
String suGetClientMacAddress( SUWebServerRequest* request )
{
if( request )
{
struct ip_addr* IPaddress;
IPAddress ip;
struct station_info* stat_info = wifi_softap_get_station_info();
String sClientIp = suGetClientIp( request );
Serial.print( "Client ip: " );
Serial.println( sClientIp );
if( sClientIp.length() > 0 )
{
while( stat_info )
{
IPaddress = &stat_info->ip;
ip = IPaddress->addr;
if( suIpAddressToString( ip ) == sClientIp )
{
// Kind of rude and ugly to exit a loop and function this way
// however it works with less 'check' overhead. OK to me.
return String( stat_info->bssid[0], HEX )+":"+
String( stat_info->bssid[1], HEX )+":"+
String( stat_info->bssid[2], HEX )+":"+
String( stat_info->bssid[3], HEX )+":"+
String( stat_info->bssid[4], HEX )+":"+
String( stat_info->bssid[5], HEX );
}
stat_info = STAILQ_NEXT(stat_info, next);
}
}
}
return "";
}
有任何提示使其在STA_MODE下工作吗?
最佳答案
暗示:
- stations (clients) connect to an AP (Access Point - server)
- an AP generally hosts RF (radio) mechanisms for the connections of stations
ESP8266可以是Station或AP,两者都不是。
除非另有特殊规定,WiFi站(作为客户端)通常不直接相互通信,例如在
mesh / Ad Hoc
网络或物理(电缆;)连接中。
关于c++ - ESP8266:如何在station模式下获取客户端的MAC地址(STA_MODE)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48894445/