A MAC (Media Access Control) address is a unique number that assigned to a network adapter by the manufacturer to uniquely identify it. A MAC address is commonly represented as a string of six hexadecimal numbers separated by colons, such as A4:CF:12:AF:C2:36
.
This tutorial shows how to get the MAC address of ESP8266 NodeMCU development board.
Components
No. | Component | Quantity |
---|---|---|
1. | ESP8266 NodeMCU + Micro USB cable | 1 |
Code
In order to get the MAC address, we can use the macAddress
member function of WiFi
global variable. We will get the MAC address as a string if no arguments provided to the function.
#include <ESP8266WiFi.h>
void setup()
{
Serial.begin(9600);
String mac = WiFi.macAddress();
Serial.println(mac);
}
void loop() {}
Also it is possible to get the MAC address stored in an unsigned char array.
#include <ESP8266WiFi.h>
void setup()
{
Serial.begin(9600);
unsigned char mac[6];
WiFi.macAddress(mac);
Serial.printf(
"%02X:%02X:%02X:%02X:%02X:%02X",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
);
}
void loop() {}
Leave a Comment
Cancel reply