An explanation on how mac addresses are derived on the ESP32:

https://docs.espressif.com/projects/esp … dress.html

An explanation for how many universal (unique) mac addresses are allocated to each ESP32

https://docs.espressif.com/projects/esp … ystem.html

Read MAC Address

8 bytes are stroed in total. 6 bytes for MAC-48, 8 bytes for EUI-64

#include "esp_mac.h"

//**********************************************************
//**********************************************************
//********** READ THIS DEVICES UNIQUE MAC ADDRESS **********
//**********************************************************
//**********************************************************
//MacAddress
//	8 byte array. (6 bytes for MAC-48, 8 bytes for EUI-64)
//Returns:
//	1 = success
//	0 = failed
int ReadFactorySetMacAddress (uint8_t *MacAddress)
{
	if (esp_efuse_mac_get_default(MacAddress) != ESP_OK)
	{
		return(1);
	}
	else
	{
		MacAddress[0] = 0;
		MacAddress[1] = 0;
		MacAddress[2] = 0;
		MacAddress[3] = 0;
		MacAddress[4] = 0;
		MacAddress[5] = 0;
		MacAddress[6] = 0;
		MacAddress[7] = 0;
		return(0);
	}
}

Display device MAC address to console


#include "esp_mac.h"

	uint8_t MacAddress[8];
	if (esp_efuse_mac_get_default(MacAddress) != ESP_OK)
		ESP_LOGI(TAG, "Unable to read MAC address");
	else
		ESP_LOGI(TAG, "MAC address: 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X", (uint16_t)MacAddress[0], (uint16_t)MacAddress[1], (uint16_t)MacAddress[2], (uint16_t)MacAddress[3], (uint16_t)MacAddress[4], (uint16_t)MacAddress[5], (uint16_t)MacAddress[6], (uint16_t)MacAddress[7]);
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *