How to set and query the MAC address of the ESP32

You can to set and query the MAC address of ESP32 in various ways. As follows:

1 Use the AT commands to set and query the MAC address of the ESP32 device

1.1 Use the AT command to set and query the MAC address of the Wi-Fi Station mode


1.2 Use the AT command to set and query the MAC address of the Wi-Fi SoftAP mode


1.3 Use the AT command to set and query the MAC address of Ethernet


1.4 Use the AT command to set and query the MAC address of BLE (BT) mode


1.5 Use the AT command to query the MAC address of the ESP32 device in current mode

The MAC address in current mode can be queried only after the ESP32 obtains the valid interface information .

  • Use the AT+CIFSR command to query the MAC address of the ESP32 device in current mode.

2 Use the esptool to set and query the MAC address of the ESP32 device

You can run the espefuse.py --h command to query the usage of related commands firstly. As follows:
How to set and query the MAC address of the ESP32

2.1 Use the esptool to query the default MAC address written into the EFUSE BLOCK0 before the ESP32 device is delivered.

  • Use the espefuse.py summary to query the default MAC address written into the EFUSE BLOCK0 before the ESP32 device is delivered. As follows:
    How to set and query the MAC address of the ESP32
  • The default MAC address in EFUSE BLOCK0 is base_mac. The default base_mac is the MAC address of the Wi-Fi Station mode. You can obtain the MAC address of the Wi-Fi SoftAP mode, Bluetooth mode, and Ethernet based on the MAC address of the Wi-Fi Station mode. Please refer to the " MAC Address " instructions. As follows:

How to set and query the MAC address of the ESP32

2.2 Use the esptool to set a Custom MAC address in EFUSE BLOCK3

  • Use the espefuse.py burn_custom_mac 12:22:33:44:55:66 command to set a Custom MAC address in EFUSE BLOCK3. As follows:

Note: The Bit 1 cannot be 1 in EFUSE BLOCK3
How to set and query the MAC address of the ESP32

2.3 Use the esptool to query the Custom MAC address in EFUSE BLOCK3

  • Use the espefuse.py get_custom_mac command to query the Custom MAC address in EFUSE BLOCK3 . As follows:
    How to set and query the MAC address of the ESP32
  • Or use the espefuse.py summary command can also query the Custom MAC address in EFUSE BLOCK3 . As follows:
    How to set and query the MAC address of the ESP32

3 Use the related APIs to set and query the MAC address of the ESP32 device

  • Use the esp_base_mac_addr_set(uint8_t *mac); API to set a Custom MAC address in EFUSE BLOCK3 as base_mac . This base_mac default is the MAC address of Wi-Fi Station mode. For example:

    	“ esp_base_mac_addr_set(12:22:33:44:55:FF)“,
    
  • The MAC addresses of other modes are as follows:

    >  STA(FF)
    >  AP(FF + 1 -> 01)
    >  BT(FF + 2 -> 02)
    >  ETH(FF + 3 -> 03)`(not-carry)`
    

Please refer to the " MAC Address " instructions. As follows:
How to set and query the MAC address of the ESP32


4 使用 NVS 写入 MAC 地址

4 Write MAC addresses using NVS


【MAC Address】

  • By scanning the QR code on the ESP32 module, we can also get the default " base_mac " address written into the EFUSE BLOCK0 before the ESP32 device is delivered .
  • The default base_mac address written into the EFUSE BLOCK0 before the ESP32 device is delivered is the MAC address of Wi-Fi Station mode. The " base_mac, +1 to the last octet " is the MAC address of Wi-Fi SoftAP mode. The " base_mac, +2 to the last octet " is the MAC address of BLE(BT) mode. The " base_mac, +3 to the last octet " is the MAC address of Ethernet .
  • The default MAC address written into the EFUSE BLOCK0 before the ESP32 device is delivered is a unique MAC address in the world, and each batch is different.
上一篇:RTOS介绍------十、Multicore Systems


下一篇:基于Arduino IDE的ESP32/ESP8266开发环境搭建