Page 1 of 1

ESP32 BLE Arduino change MAC after initialization

Posted: Mon Feb 14, 2022 11:28 am
by markusberger87
Hi,

I am using the ESP32 BLE Arduino -> BLE_IBeacon example in Arduino IDE and would like to be able to change the MAC-Address of the advertising device after I initialized the BLEDevice.

Right now it looks like this:

Code: Select all

uint8_t new_mac[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
esp_base_mac_addr_set(new_mac);
BLEDevice::init("ESP32");
BLEDevice::startAdvertising();
This changes the BLE-MAC-Address before initializing the BLEDevice. After the initialization

Code: Select all

esp_base_mac_addr_set(new_mac);
does not work anymore and the advertised mac stays the same. The only way I found to change it was to use

Code: Select all

ESP.restart();
but this erases everything.

I know it is possible, because
https://docs.espressif.com/projects/esp ... m-base-mac
says "It is also possible to call the function esp_netif_set_mac() to set the specific MAC used by a network interface, after network initialization.", but I can't make it work.

I tried including the necessary libraries and using esp_netif_set_mac(), but I don't know how to get the esp_netif Parameter.

Can someone help me or show me a working example please?