1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

add function to get the MAC / BSSID as String

This commit is contained in:
Markus Sattler 2015-05-28 17:31:45 +02:00
parent 883278ae4e
commit c415ebe8b4
2 changed files with 61 additions and 3 deletions

View File

@ -203,12 +203,32 @@ uint8_t* ESP8266WiFiClass::macAddress(uint8_t* mac)
return mac; return mac;
} }
String ESP8266WiFiClass::macAddress(void)
{
uint8_t mac[6];
char macStr[18] = {0};
wifi_get_macaddr(STATION_IF, mac);
sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return String(macStr);
}
uint8_t* ESP8266WiFiClass::softAPmacAddress(uint8_t* mac) uint8_t* ESP8266WiFiClass::softAPmacAddress(uint8_t* mac)
{ {
wifi_get_macaddr(SOFTAP_IF, mac); wifi_get_macaddr(SOFTAP_IF, mac);
return mac; return mac;
} }
String ESP8266WiFiClass::softAPmacAddress(void)
{
uint8_t mac[6];
char macStr[18] = {0};
wifi_get_macaddr(SOFTAP_IF, mac);
sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return String(macStr);
}
IPAddress ESP8266WiFiClass::localIP() IPAddress ESP8266WiFiClass::localIP()
{ {
struct ip_info ip; struct ip_info ip;
@ -251,6 +271,16 @@ uint8_t* ESP8266WiFiClass::BSSID(void)
return reinterpret_cast<uint8_t*>(conf.bssid); return reinterpret_cast<uint8_t*>(conf.bssid);
} }
String ESP8266WiFiClass::BSSIDstr(void)
{
static struct station_config conf;
char mac[18] = {0};
wifi_station_get_config(&conf);
sprintf(mac,"%02X:%02X:%02X:%02X:%02X:%02X", conf.bssid[0], conf.bssid[1], conf.bssid[2], conf.bssid[3], conf.bssid[4], conf.bssid[5]);
return String(mac);
}
int32_t ESP8266WiFiClass::channel(void) { int32_t ESP8266WiFiClass::channel(void) {
return wifi_get_channel(); return wifi_get_channel();
} }
@ -358,6 +388,17 @@ uint8_t * ESP8266WiFiClass::BSSID(uint8_t i)
return it->bssid; return it->bssid;
} }
String ESP8266WiFiClass::BSSIDstr(uint8_t i)
{
char mac[18] = {0};
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));
if (!it)
return String("");
sprintf(mac,"%02X:%02X:%02X:%02X:%02X:%02X", it->bssid[0], it->bssid[1], it->bssid[2], it->bssid[3], it->bssid[4], it->bssid[5]);
return String(mac);
}
int32_t ESP8266WiFiClass::channel(uint8_t i) int32_t ESP8266WiFiClass::channel(uint8_t i)
{ {
struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i)); struct bss_info* it = reinterpret_cast<struct bss_info*>(_getScanInfoByIndex(i));

View File

@ -103,16 +103,19 @@ public:
* Get the station interface MAC address. * Get the station interface MAC address.
* *
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH * return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
* return: String
*/ */
uint8_t* macAddress(uint8_t* mac); uint8_t* macAddress(uint8_t* mac);
String macAddress(void);
/* /*
* Get the softAP interface MAC address. * Get the softAP interface MAC address.
* *
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH * return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
* return: String
*/ */
uint8_t* softAPmacAddress(uint8_t* mac); uint8_t* softAPmacAddress(uint8_t* mac);
String softAPmacAddress(void);
/* /*
* Get the station interface IP address. * Get the station interface IP address.
* *
@ -151,10 +154,17 @@ public:
/* /*
* Return the current bssid / mac associated with the network if configured * Return the current bssid / mac associated with the network if configured
* *
* return: bssid string * return: bssid uint8_t *
*/ */
uint8_t * BSSID(void); uint8_t * BSSID(void);
/*
* Return the current bssid / mac associated with the network if configured
*
* return: bssid string
*/
String BSSIDstr(void);
/* /*
* Return the current channel associated with the network * Return the current channel associated with the network
* *
@ -208,10 +218,17 @@ public:
/** /**
* return MAC / BSSID of scanned wifi * return MAC / BSSID of scanned wifi
* @param networkItem specify from which network item want to get the information * @param networkItem specify from which network item want to get the information
* @return uint8_t * to MAC / BSSID of scanned wifi * @return uint8_t * MAC / BSSID of scanned wifi
*/ */
uint8_t * BSSID(uint8_t networkItem); uint8_t * BSSID(uint8_t networkItem);
/**
* return MAC / BSSID of scanned wifi
* @param networkItem specify from which network item want to get the information
* @return String MAC / BSSID of scanned wifi
*/
String BSSIDstr(uint8_t networkItem);
/** /**
* return channel of scanned wifi * return channel of scanned wifi
* @param networkItem specify from which network item want to get the information * @param networkItem specify from which network item want to get the information