您的位置:首页 > 娱乐 > 明星 > 代理服务器免费网页版_兰州百姓网免费发布信息网站_好看的网站模板_国内优秀网页设计赏析

代理服务器免费网页版_兰州百姓网免费发布信息网站_好看的网站模板_国内优秀网页设计赏析

2025/7/15 7:12:21 来源:https://blog.csdn.net/cnnews/article/details/145066084  浏览:    关键词:代理服务器免费网页版_兰州百姓网免费发布信息网站_好看的网站模板_国内优秀网页设计赏析
代理服务器免费网页版_兰州百姓网免费发布信息网站_好看的网站模板_国内优秀网页设计赏析

在<esp_mac.h>中申明了一个函数,esp_err_t esp_iface_mac_addr_set(const uint8_t *mac, esp_mac_type_t type);可以通过它修改ESP32的mac,其中type是枚举类型,定义如下:

typedef enum {ESP_MAC_WIFI_STA,      /**< MAC for WiFi Station (6 bytes) */ESP_MAC_WIFI_SOFTAP,   /**< MAC for WiFi Soft-AP (6 bytes) */ESP_MAC_BT,            /**< MAC for Bluetooth (6 bytes) */ESP_MAC_ETH,           /**< MAC for Ethernet (6 bytes) */ESP_MAC_IEEE802154,    /**< if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC for IEEE802154 (8 bytes) */ESP_MAC_BASE,          /**< Base MAC for that used for other MAC types (6 bytes) */ESP_MAC_EFUSE_FACTORY, /**< MAC_FACTORY eFuse which was burned by Espressif in production (6 bytes) */ESP_MAC_EFUSE_CUSTOM,  /**< MAC_CUSTOM eFuse which was can be burned by customer (6 bytes) */ESP_MAC_EFUSE_EXT,     /**< if CONFIG_SOC_IEEE802154_SUPPORTED=y, MAC_EXT eFuse which is used as an extender for IEEE802154 MAC (2 bytes) */
} esp_mac_type_t;

这里修改四个类型的mac

#include <esp_mac.h>void mac_set() {uint8_t mac_address[6];esp_err_t err;uint8_t len;err = esp_base_mac_addr_get(mac_address);if (err == ESP_OK){printf("MAC Address: " MACSTR "\n\n", mac_address[0], mac_address[1], mac_address[2], mac_address[3], mac_address[4], mac_address[5]);}else{printf("Failed to read MAC address: %s\n\n", esp_err_to_name(err));}mac_address[5] += 9;len = esp_iface_mac_addr_set(mac_address,ESP_MAC_WIFI_STA);printf("%d bytes has set\n\n",len);len = esp_iface_mac_addr_set(mac_address,ESP_MAC_BASE);printf("%d bytes has set\n\n",len);len = esp_iface_mac_addr_set(mac_address,ESP_MAC_EFUSE_FACTORY);printf("%d bytes has set\n\n",len);len = esp_iface_mac_addr_set(mac_address,ESP_MAC_EFUSE_CUSTOM);printf("%d bytes has set\n\n",len);
}

结果

MAC Address: e8:06:90:97:fa:500 bytes has set0 bytes has setE (4089) system_api: EFUSE MAC can not be set using this API
2 bytes has setE (4092) system_api: EFUSE MAC can not be set using this API
2 bytes has set

然后用前一篇谈到的获取mac看看最后是什么

WiFi.macAddress::MAC Address: E8:06:90:97:FA:50MAC Type: 0 (ESP_MAC_WIFI_STA)
MAC Address: e8:06:90:97:fa:59MAC Type: 1 (ESP_MAC_WIFI_SOFTAP)
MAC Address: e8:06:90:97:fa:51MAC Type: 2 (ESP_MAC_BT)
MAC Address: e8:06:90:97:fa:5bMAC Type: 3 (ESP_MAC_ETH)
MAC Address: e8:06:90:97:fa:5cMAC Type: 4 (ESP_MAC_IEEE802154)
E (4130) system_api: 4 mac type is incorrect (not found)
Failed to read MAC address: ESP_ERR_NOT_SUPPORTEDMAC Type: 5 (ESP_MAC_BASE)
MAC Address: e8:06:90:97:fa:59MAC Type: 6 (ESP_MAC_EFUSE_FACTORY)
MAC Address: e8:06:90:97:fa:50MAC Type: 7 (ESP_MAC_EFUSE_CUSTOM)
E (4155) system_api: eFuse MAC_CUSTOM is empty
E (4160) system_api: unsupported mac type
E (4165) system_api: MAC address generation error
Failed to read MAC address: ESP_ERR_NOT_SUPPORTEDMAC Type: 8 (ESP_MAC_EFUSE_EXT)
E (4178) system_api: 8 mac type is incorrect (not found)
Failed to read MAC address: ESP_ERR_NOT_SUPPORTED

结论:

通过esp_iface_mac_addr_set(),能修改ESP_MAC_WIFI_STA、ESP_MAC_BASE,不能修改ESP_MAC_EFUSE_FACTORY

用esp_base_mac_addr_get()和WiFi.macAddress()读取的mac就是ESP_MAC_EFUSE_FACTORY类型的地址,可以作为模块的唯一ID

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com