How to get ESP-32 Chip ID using SDK?

iwemos
Posts: 3
Joined: Fri Jun 17, 2016 1:18 am

How to get ESP-32 Chip ID using SDK?

Postby iwemos » Wed Apr 19, 2017 6:57 am

I want to get ESP-32's Chip ID.
How to get ESP-32 Chip ID using SDK?

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: How to get ESP-32 Chip ID using SDK?

Postby ESP_igrr » Wed Apr 19, 2017 8:30 am

The chip ID is essentially its MAC address. You can use esp_efuse_read_mac function declared in esp_system.h

iwemos
Posts: 3
Joined: Fri Jun 17, 2016 1:18 am

Re: How to get ESP-32 Chip ID using SDK?

Postby iwemos » Fri Apr 21, 2017 2:14 am

I use this code:

Code: Select all

    uint8_t chipid[6];
    esp_efuse_read_mac(chipid);
    Serial.printf("%X\n",chipid);
But the chipid always is 3FFCC82C with different ESP32 IC, why? :?:

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: How to get ESP-32 Chip ID using SDK?

Postby ESP_Angus » Fri Apr 21, 2017 2:27 am

The MAC address is an array of bytes not a single integer, so when you printf in this way you're printing the address of the array in RAM.

Try something like

Code: Select all

Serial.printf("%02x:%02x:%02x:%02x:%02x:%02x\n",chipid[0], chipid[1], chipid[2], chipid[3], chipid[4], chipid[5]);

iwemos
Posts: 3
Joined: Fri Jun 17, 2016 1:18 am

Re: How to get ESP-32 Chip ID using SDK?

Postby iwemos » Fri Apr 21, 2017 3:28 am

Thank you.

meneldor
Posts: 75
Joined: Mon Dec 25, 2017 7:28 am

Re: How to get ESP-32 Chip ID using SDK?

Postby meneldor » Thu Apr 26, 2018 9:59 am

Hello,
As esp_efuse_read_mac is deprecated but esp_efuse_mac_get_default returns 0 what to use to get the unique id for the chip?

EDIT: sorry, esp_efuse_mac_get_default doesn't return 0,my fault. What's the difference between this function and esptool's chip_id which has some additional chars?

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: How to get ESP-32 Chip ID using SDK?

Postby ESP_Angus » Thu Apr 26, 2018 11:53 pm

The esptool.py chip_id function is printing the MAC address CRC byte in the highest byte of the output, and losing the lowest byte of the MAC entirely. This is a bug, probably the chip_id function should do nothing on ESP32 (or alias to read_mac).

meneldor
Posts: 75
Joined: Mon Dec 25, 2017 7:28 am

Re: How to get ESP-32 Chip ID using SDK?

Postby meneldor » Sun Apr 29, 2018 11:40 am

Thanks, Angus. I will use only the MAC as unique id.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: How to get ESP-32 Chip ID using SDK?

Postby ESP_Angus » Sun Apr 29, 2018 11:25 pm

Update to this, in v2.4.0 (currently in development on the master branch), "esptool.py chip_id" will alias to read_mac for ESP32.

(chip_id on ESP8266 is still the 3 least significant bytes of the MAC, so it's still possible to have an equivalent 24-bit "ID" on ESP32 if you need one. But better to use the full MAC if you can, as the lower 24-bits may collide.)

RiverS_16
Posts: 7
Joined: Mon Sep 25, 2023 3:54 am

Re: How to get ESP-32 Chip ID using SDK?

Postby RiverS_16 » Fri Dec 01, 2023 9:20 am

hello,

I had a query regarding MAC Address ,

1.is MAC Address configurable? as i read in the documentation esp_base_mac_addr_set () can be used to set custom base address.

2.which API to use to get UID of the chip.

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 90 guests