This is an old revision of the document!
Each network card is supposed to have a unique physical address called a MAC address. MAC abbreviation stands for Medium Access Control protocol, which provides access to the physical link in the network layer. The STM32WB55 SoC doesn't have a WiFi network controller so our STM laboratory stands have the WiFi module based on ESP32-C3 SoC connected by serial port additional ESP32-C3 module and controlled with AT commands. To learn how to use these commands please refer to the STM_IoT_Intro chapter.
ESP32 chip has built-in MAC. MAC can be used to identify devices, but note that it is not a “strong” ID: it can be programmatically changed and easily discovered. In the following scenario, we only present how to read the MAC address. A part regarding displaying on the selected screen is up to the developer. You can refer to the appropriate scenario, as listed below.
To implement this scenario, it is necessary to get familiar with at least one of the following scenarios first:
Present a MAC address on the selected display. The steps below present the reading part and display it on LCD. This display has 16 characters per line, but the commonly used format for MAC addresses requires 17 characters. If you want to see the full MAC address modify the example and use the display other than LCD.
Check if you can see a full LCD in your video stream. Book a device and create a dummy Arduino file with void setup()…
and void loop()…
.
Include the WiFi management library in your source code:
#include <WiFi.h>
The WiFi library automatically initialises a singleton class WiFi
that you can use to set up working mode, read MAC, and perform many other operations.
Reading the MAC as a String
is as easy as simply calling:
WiFi.macAddress();
Using another node should change the MAC read. Book another device and discover its MAC.
Can I change MAC?: Actually, yes, you can. It is not advised, however, because you may accidentally generate an overlapping address that will collide with another device in the same network. You must first explicitly configure the ESP32 chip to work as an AP (Access Point, Server) or STA (WiFi Client) to do it. Sample stub code (for STA) may look as follows:
#include <WiFi.h> #include <esp_wifi.h> uint8_t newMAC[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE}; //Array of bytes with new MAC void setup() { WiFi.mode(WIFI_STA); esp_wifi_set_mac(WIFI_IF_STA, &newMAC[0]); }