Page 1 of 1

Clarification on ESP32 MAC Address Uniqueness and Identification

Posted: Mon Mar 03, 2025 6:45 am
by Harshitha.R
Dear ESP-IDF Support Team,

I hope you are doing well.

We are currently working with ESP32 devices and using the 12-character hexadecimal MAC address assigned to each chip for identification purposes. At present, we are considering only the last six characters of the MAC address as the unique identifier. We would like to confirm if this is the correct approach.

Additionally, we would like to understand whether the first six characters of the MAC address remain the same for a certain batch of ESP32 chips produced. Could you provide clarity on how the MAC addresses are assigned and which specific characters within the MAC address are guaranteed to be unique across all ESP32 chips?

Your insights on this would be greatly appreciated.

Looking forward to your response

Re: Clarification on ESP32 MAC Address Uniqueness and Identification

Posted: Mon Mar 03, 2025 7:34 am
by Sprite
By definition, you need all 6 bytes (aka all 12 hex characters) of the MAC address (technically 5 bytes and 6 out of the 8 bits of the remaining byte) to be sure to have a globally unique number; I don't think we cannot guarantee any unique-ness for only a subset of these 6 bytes.

Could you clarify what issue you're running into where you think only sending a subset of the mac-address is a solution? Perhaps there's another way of solving the issue.

Re: Clarification on ESP32 MAC Address Uniqueness and Identification

Posted: Thu Mar 06, 2025 10:17 am
by egionet
Based on other posts, the MAC address should be unique for every device produced.

Basic chip identification example:

Code: Select all

uint32_t get_chip_id(void) {
    uint32_t chipid = 0L;
    for (int i = 0; i < 17; i = i + 8) {
        chipid |= ((get_efuse_mac() >> (40 - i)) & 0xff) << i;
    }
    return chipid;
}

uint64_t get_efuse_mac(void) {
    uint64_t chipmacid = 0LL;
    esp_efuse_mac_get_default((uint8_t *)(&chipmacid));
    return chipmacid;
}

Re: Clarification on ESP32 MAC Address Uniqueness and Identification

Posted: Thu Mar 06, 2025 10:47 am
by djixon
You can not hold uniqueness of MAC within 32 bit variable. 6 bytes of MAC address require 64 bit holder. Since ESP32 follows little Endianitess, if those 6 bytes are stored somewhere in memory you can access them like uint64 MAC = *(uint64_t *) (address in memory where MAC is located) . Similar way is used in second function in your example, where uint8_t* is dereferenced as 64 bit result of the function which is correct. You should not relly on any's companny choices (or range approvals for BLE or WiFi from BLE commite). Only what is important for your application is that two devices nearby will not share the same MAC even if they share the same name.

To identify what "makes the device for opting it in discovered device list" is your own functionality integrated within device which, once read by your apps, can serve to decision of what to do next, or discard device.

Of course, you can make your ie. PC application, (or client application on another ESP32 device) dependent on specific MAC device address, but then it will work only with that single particular ESP32 chip. However, if your app is cappable to recognize all devices of the same functionality you provided in those devices, you will use services to obtain those capabilities or user custom identifier (if it is supported by standard you want to incorporate in your devices) which in that case can serve as "user unique identifier of device cappabilities". So its not about MAC but actually service UUID in such a cases.

Re: Clarification on ESP32 MAC Address Uniqueness and Identification

Posted: Thu Mar 06, 2025 12:05 pm
by egionet
Depends on your use case; this isn't an uncommon post. My example for the chip-id could leverage the 6 bytes as A 64-bit value quite easily, it was simply an example. Likewise, you could leverage a generated UUID with nvs.