Page 1 of 1

获取esp32s3唯一ID

Posted: Tue Mar 14, 2023 8:59 am
by hello_meeyo
Dear 大神们:
你们好,请问下esp32s3通过esp_read_mac这个函数读取到mac地址是否是唯一的ID呢。会不会有重复的问题。因为我想用一个唯一ID来区别我的设备。thks。

Re: 获取esp32s3唯一ID

Posted: Wed Mar 15, 2023 2:40 am
by jr-test

Code: Select all

#define _MAC2STR_(a) (a)[0],(a)[1],(a)[2],(a)[3],(a)[4],(a)[5]
#define _MACSTR_ "%02X:%02X:%02X:%02X:%02X:%02X"

//定义Mac地址存储空间
uint8_t mac_addr[6] = {0};
//获取Mac地址
esp_efuse_mac_get_default(mac_addr);
//打印Mac地址
printf("" _MACSTR_ "\n",_MAC2STR_(mac_addr));
试试这个行不行?

Re: 获取esp32s3唯一ID

Posted: Wed Mar 15, 2023 6:44 am
by hello_meeyo
Dear jr-test:
你好,请问下您给的esp_efuse_mac_get_default跟我之前调用的esp_read_mac函数有什么不同呢?我之前那个函数能读出值,但是我不知道是否是唯一ID。THKS。

Re: 获取esp32s3唯一ID

Posted: Wed Mar 15, 2023 6:50 am
by hello_meeyo
我用esp_read_mac读出来的地址是:
[0;32mI (564) BT MAC: 0xf4, 0x12, 0xfa, 0xe6, 0xcc, 0x6
而用esp_efuse_mac_get_default读出来的地址是:
[0;32mI (794) esp_efuse_mac_get_default read BT MAC: 0xf4, 0x12, 0xfa, 0xe6, 0xcc, 0x4[0m
最后一个字节不一样。是这两函数有什么不同吗?thks。

Re: 获取esp32s3唯一ID

Posted: Wed Mar 15, 2023 7:19 am
by jr-test
456.png
456.png (44.56 KiB) Viewed 3048 times
你得看看两个函数定义是怎样的了,我把函数定义在下面给你贴出来。或者找乐鑫官方的工程师问问。

Code: Select all

/**
  * @brief  Return base MAC address which is factory-programmed by Espressif in EFUSE.//返回由Espressif在EFUSE中工厂编程的基本MAC地址。
  *
  * @param  mac base MAC address, length: 6 bytes/8 bytes.
  *         length: 6 bytes for MAC-48
  *                 8 bytes for EUI-64(used for IEEE 802.15.4)
  *
  * @return ESP_OK on success
  *         ESP_ERR_INVALID_ARG mac is NULL
  */
esp_err_t esp_efuse_mac_get_default(uint8_t *mac);

/**
  * @brief  Read base MAC address and set MAC address of the interface.//读取基本MAC地址并设置接口的MAC地址。
  *
  * This function first get base MAC address using esp_base_mac_addr_get().
  * Then calculates the MAC address of the specific interface requested,
  * refer to ESP-IDF Programming Guide for the algorithm.
  *
  * @param  mac base MAC address, length: 6 bytes/8 bytes.
  *         length: 6 bytes for MAC-48
  *                 8 bytes for EUI-64(used for IEEE 802.15.4)
  * @param  type Type of MAC address to return
  *
  * @return ESP_OK on success
  */
esp_err_t esp_read_mac(uint8_t *mac, esp_mac_type_t type);