Esp32

How to Get ESP32 WiFi Station Interface MAC Address Using Arduino IDE

ESP32 is a microcontroller-based power conserving board that takes instructions from users and after processing them convert into output using the Tensilica Xtensa LX6 ESP32 smart chip. ESP32 comes with a WiFi driver module that can configure it in different WiFi modes such as station mode, access point mode or both. This article will cover the Arduino code for getting the MAC address of ESP32 in Station point mode.

Introduction to ESP32 WiFi Station Mode

The ESP32 is a low-cost, low-power microcontroller with built-in Wi-Fi and Bluetooth capabilities. It is commonly used in the Internet of Things (IoT) and other applications that require connectivity and processing power.

In station mode, the ESP32 connects to a wireless access point (AP) and acts as a client, allowing it to access the internet and communicate with other devices on the same network. This is in contrast to access point mode, where the ESP32 acts as a wireless AP and allows other devices to connect to it.

Station mode is useful for applications where the ESP32 needs to connect to a pre-existing network, such as a home or office Wi-Fi network. It is also useful for applications where the ESP32 needs to send data to a server or receive data from other devices on the network.

To connect ESP32 in station point mode first we have to configure it using the command:

WiFi.mode(WIFI_STA);

Getting ESP32 WiFi Station Interface MAC Address Using Arduino IDE

For getting ESP32 MAC address in station point mode first we have to configure ESP32 in station mode. After that, using the MAC address WiFi library variable, we can print the MAC address of ESP32 station interface on Arduino IDE serial monitor.

Code
Open the Arduino IDE and upload code to the ESP32 board:

#include "WiFi.h"  /*included WiFi library*/
 
void setup(){
  Serial.begin(115200); /*defined baud rate*/
 
  WiFi.mode(WIFI_MODE_STA); /*configured ESP32 WiFi in Station Mode*/
  Serial.print("ESP32 Station Interface MAC Address: ");
  Serial.println(WiFi.macAddress());  /*Prints ESP32 MAC address in Station Mode*/
}
 
void loop(){   }

Code started by including the necessary WiFi library. This library helps to control ESP32 WiFi modes and using the variable of this library we can print the MAC address of ESP32 when it is configured in different WiFi modes such as access point, station, or both.

Next baud rate is initialized for serial communication between Arduino IDE and ESP32 board.

After that, using the WiFi library, we will call the Station mode function to establish ESP32 connection in station point mode using the command WiFi.mode(WIFI_MODE_STA). Once ESP32 is configured in station point mode it can be connected to any network by defining the SSID and password for that network.

At last, using the WiFi.macAddress() command ESP32 will print its MAC address on the serial monitor of Arduino IDE.

Output
In output we can see the station interface MAC address of ESP32:

3

Conclusion

ESP32 is an IoT board which helps to convert any project into a complete wireless-based project using the in-built WiFi driver’s modules. Sometimes we need to use the mac address for security of devices inside the wireless network. This article will help to get the ESP32 MAC address when it is configured in station point mode.

About the author

Kashif

I am an Electrical Engineer. I love to write about electronics. I am passionate about writing and sharing new ideas related to emerging technologies in the field of electronics.