Code: Select all
#include <WiFi.h>
#include <esp_wifi.h>
// 自定义MAC地址(请替换为你需要的地址)
uint8_t customMac[] = {0x22, 0xBC, 0x5A, 0x0A, 0x6C, 0x88}; // 必须符合当地法规
// 自定义AP热点的配置
const char *ap_ssid = "test";
const char *ap_password = "test1234; // AP密码至少8字符
void setup() {
Serial.begin(115200);
Serial.println("\n正在设置AP模式MAC地址...");
setApMac(customMac); // 设置新的AP MAC地址
Serial.println("初始化AP模式...");
WiFi.softAP(ap_ssid, ap_password);
// 打印AP MAC地址
Serial.print("AP MAC已设置为: ");
Serial.println(WiFi.softAPmacAddress());
Serial.printf("热点已创建! SSID: %s\n", ap_ssid);
}
void loop() {
delay(1000); // 空循环
}
// =================================================================
// 设置AP模式MAC地址的函数
// =================================================================
void setApMac(const uint8_t *mac) {
// 注意:AP模式MAC必须满足特定条件(通常是首位为0x02)
uint8_t ap_mac[6];
memcpy(ap_mac, mac, 6);
ap_mac[0] |= 0x22; // 确保是有效的本地MAC地址
esp_wifi_set_mac(WIFI_IF_AP, ap_mac); // 设置AP接口的MAC
}