Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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 "";
- }
Add Comment
Please, Sign In to add comment