Hey together.
I use an Arduino Nano ESP32 and the Arduino IDE 2.3.2.
I'm currently talking to our IT department to connect to our internal WiFi and I need to tell them the MAC address of my Nano.
So is it possible at all to print the MAC address without a connection? Because I tried different example codes, but really none worked.. or am I just doing something wrong?
Thank you!
J-M-L
July 3, 2024, 2:21pm
2
read this information on ESP32 Mac addresses. (note that the MAC address differs depending on wether you are a station or an access point).
and try this
#include "esp_mac.h"
void setup() {
uint8_t mac[6] = {0};
esp_err_t ret = ESP_OK;
Serial.begin(115200);
ret = esp_read_mac(mac, ESP_MAC_EFUSE_FACTORY);
if (ret != ESP_OK) {
Serial.printf("Failed to get base MAC address from EFUSE BLK0. (%s)", esp_err_to_name(ret));
} else {
Serial.printf("MAC Address: %02X:%02X:%02X:%02X:%02X:%02X\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
}
void loop() {}
I get an error that ESP_MAC_EFUSE_FACTORY
is not defined
J-M-L
July 3, 2024, 2:38pm
4
OK that's code for the ESP32, I don't have a "Nano ESP32" so I'm not sure how you get access to the ESP32 features / APIs
No worries! I'll use the Nano ESP32 as Station. FYI.
J-M-L
July 3, 2024, 2:50pm
6
can you try to add #include <WiFi.h>
at the start of the code ?
Compilation error: 'ESP_MAC_EFUSE_FACTORY' was not declared in this scope
#include "esp_mac.h"
#include "Arduino.h"
#include "WiFi.h"
uint8_t mac[8];
uint8_t cam[6];
void setup() {
Serial.begin(115200);
esp_efuse_mac_get_default(mac);
WiFi.macAddress(cam);
}
void loop() {
// Method esp_efuse_mac_get_default
Serial.printf("esp_efuse_mac_get_default MAC Address: %02X:%02X:%02X:%02X:%02X:%02X\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
// Method 1
Serial.printf("Method 1 MAC Address: %02X:%02X:%02X:%02X:%02X:%02X\n", cam[0], cam[1], cam[2], cam[3], cam[4], cam[5]);
// Method 2
Serial.printf("Method 2 MAC Address: %s\n", WiFi.macAddress().c_str());
delay(20000);
}
Used this now