ESP 8266 mac address change in AP mode

Hello,

I would like to change ESP 8266's mac address in AP mode. Unfortunately, it only works in STA mode. Is there any way to make it work in AP mode?

Thanks,

Hmm,
doesn't this work ?

#include <ESP8266WiFi.h>

// Set your new MAC Address
uint8_t newMACAddress[] = {0x32, 0xAE, 0xA4, 0x07, 0x0D, 0x66};

void setup(){
  Serial.begin(115200);
  Serial.println();
  
  WiFi.mode(WIFI_STA);  //WiFi.mode(WIFI_AP_STA); edit, it needs to be in station mode to begin with
  
  Serial.print("[OLD] ESP8266 Board MAC Address:  ");
  Serial.println(WiFi.macAddress());

  // For Soft Access Point (AP) Mode
  wifi_set_macaddr(SOFTAP_IF, &newMACAddress[0]);
  // For Station Mode
  wifi_set_macaddr(STATION_IF, &newMACAddress[0]);
  
  Serial.print("[NEW] ESP8266 Board MAC Address:  ");
  Serial.println(WiFi.macAddress());
}
 
void loop(){

}

Unfortunately, no. It only works in STA mode only; I got a new mac (in the terminal Wifi.macAddress()). But the wifi analyser app displays the original mac instead of the new one in AP mode.

 delay(1000);
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  wifi_set_macaddr(SOFTAP_IF, &newMACAddress[0]);
  wifi_set_macaddr(STATION_IF, &newMACAddress[0]);

  Serial.println();
  Serial.print("Configuring access point...\n");
  WiFi.softAP(ssid, password);
  WiFi.softAPConfig(local_ip, gateway, subnet);
  IPAddress myIP = WiFi.softAPIP();
  
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  Serial.println(WiFi.macAddress());

That is unfortunate. It also doesn't appear to be persistent. I will investigate a bit more later.

If you understood what a MAC is and how it is assigned, maybe then you would understand why you see what you see. I was shocked to discover it could be changed at all.

Times, they are changing … (Bob Dylan)

Ok i did some more research and i found this as a very likely solution

#include <ESP8266WiFi.h>

//extern "C" {
  #include "user_interface.h"
//}
void initVariant() {
  uint8_t mac[] = {0x36, 0x33, 0x33, 0x33, 0x33, 0x33};
  wifi_set_macaddr(SOFTAP_IF, &mac[0]);
}

void setup() {
  Serial.begin(115200); Serial.println();
  Serial.print("This node AP mac: "); Serial.println(WiFi.softAPmacAddress());
  WiFi.mode(WIFI_STA);
  Serial.print("This node AP (STA) mac: "); Serial.println(WiFi.softAPmacAddress());
  delay(3000);
  // WiFi.mode(WIFI_AP); // <----- without this wifi_set_macaddr wont work
  ESP.restart();
}

void loop() {
}

Unfortunately combining them doesn't result in what i thought i should be getting. I don't really read MAC addresses anywhere, so testing will be all on your side.

I even had some trouble compiling for ESP8285 boards (which most of my ESP-01 's are) and apparently there is 2 ways of including "user_interface.h"

Also my results appear to be core specific up to some extend. I'll dig up a nodeMCU and see what happens later on, because the ESP-01 i have may not be always doing the same as such a board