Setting up Arduino as softAP and getting exact mac address.

I'm attempting to set up an Arduino as a soft access point. It's function will be someone connects to it and it spits out that connecting devices mac address.

So, I added some code to get the mac address of all devices connected to that access point. The problem is that the mac address I access from bssid isn't the same as the one displayed from the connecting device using ifconfig.

Here is the code I'm using:

#include <ESP8266WiFi>

/* configuration  wifi */
const char *ssid = "circuits4you.com";
const char *pass = "password";

void setup() {
 delay(1000);
 Serial.begin(115200);
 Serial.println();
 Serial.print("Configuring access point...");
 
 WiFi.softAP(ssid,pass);
 
 IPAddress myIP = WiFi.softAPIP();
 
 Serial.print("AP IP address: ");
 Serial.println(myIP);
}

void loop() {
 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 Clients are = ");
 Serial.println(number_client);
 
   while (stat_info != NULL) {
     
     Serial.print("client= ");
     
     Serial.print(i);
     Serial.print(" with MAC adress is = ");
     
     Serial.print(stat_info->bssid[0],HEX);Serial.print(" ");
     Serial.print(stat_info->bssid[1],HEX);Serial.print(" ");
     Serial.print(stat_info->bssid[2],HEX);Serial.print(" ");
     Serial.print(stat_info->bssid[3],HEX);Serial.print(" ");
     Serial.print(stat_info->bssid[4],HEX);Serial.print(" ");
     Serial.print(stat_info->bssid[5],HEX);Serial.print(" ");
     
     stat_info = STAILQ_NEXT(stat_info, next);
     i++;
     Serial.println();
   }
   
 delay(500);
}

So, the mac address I get from bssid would be different from the mac address from the device using ifconfig. Specifically, it'll print the correct mac address for certain devices (bssid and device number match) but on some occasions hex digits will be changed / missing.

I've done some research and understand that the bssid isn't the exact mac address? I'm not really sure. Is there a way to do this?

If this isn't specific enough let me know as its my first time posting on this forum.

Thanks in advance!

Hi. Please read the forum guide in the sticky post, then modify your post above and put in the code tags. Thanks.

Are you confusing MAC addresses and IP addresses? You mention MAC addresses, but your code prints IP addresses.

A MAC address is a unique 6-byte code burned into a device during manufacture.

An IP address is a 4 byte code assigned by your router/access point at the time a device connects.

I thought that the BSSID is the mac address.

Perhaps I am confused about that. But what I want to access is this exactly after running ifconfig :

enp4s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether XX:XX:XX:XX:XX:XX <-- This number.

I was under the impression that that number is the mac address for that device?

Does that make sense.

KUMA_SAN:
I thought that the BSSID is the mac address.

Perhaps I am confused about that. But what I want to access is this exactly after running ifconfig :

enp4s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether XX:XX:XX:XX:XX:XX <-- This number.

I was under the impression that that number is the mac address for that device?

Does that make sense.

only access points have BSSID. MAC address of the AP can be used as BSSID.

from reference:
wifi_softap_get_station_info
This API depends on DHCP, so it cannot get static IP, etc. in case DHCP is not used.

struct station_info * station = wifi_softap_get_station_info();
while(station){
    os_printf(bssid : MACSTR, ip : IPSTR/n,
             MAC2STR(station->bssid), IP2STR(&station->ip));
    station = STAILQ_NEXT(station, next);
}
wifi_softap_free_station_info();

Thanks for putting in the code tags. +1 karma

Thanks everyone for responding!

Turns out it was a formatting issue. I was able to fix it with this bit of code:

 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();
  
  Serial.print(station_mac); Serial.print(" "); Serial.println(station_ip);
  
  station_list = STAILQ_NEXT(station_list, next);
  }