This is an old revision of the document!


STM_IoT_1: Reading MAC address of the WiFi

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 present how to read and display the MAC address on LCD. Displaying on other display than LCD is up to the developer. You can refer to the appropriate scenario, as listed below.

Prerequisites

To implement this scenario, it is necessary to get familiar with at least one of the following scenarios first:

Suggested Readings and Knowledge Resources

Hands-on Lab Scenario

Task to be implemented

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. For seeing the full MAC address modify the example and use the display other than LCD.

The MAC addresses usually are expressed as six hexadecimal numbers separated by colons eg. “84:fc:e6:88:69:d5”.

Start

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()….

Steps

Step 1

Include the LCD library in your source code:

#include "LiquidCrystal.h"

Create objects of the LCD and Hardware Serial classes:

// Serial port class and configuration (Constructor uses STM port numbering)
HardwareSerial WiFiSerial(RxD_PIN, TxD_PIN, NC, NC);
 
// LCD class
const int rs = PC5, en = PB11, d4 = PB12, d5 = PB13, d6 = PB14, d7 = PB15;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

Step 2

In the Setup() function initialise the serial port and display.

    WiFiSerial.begin(115200);
    lcd.begin(16, 2);

Use the code template from

Result validation

Using another node should change the MAC read. Book another device and discover its MAC.

FAQ

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]);
}

Project information


This Intellectual Output was implemented under the Erasmus+ KA2.
Project IOT-OPEN.EU Reloaded – Education-based strengthening of the European universities, companies and labour force in the global IoT market.
Project number: 2022-1-PL01-KA220-HED-000085090.

Erasmus+ Disclaimer
This project has been funded with support from the European Commission.
This publication reflects the views of only the author, and the Commission cannot be held responsible for any use that may be made of the information contained therein.

Copyright Notice
This content was created by the IOT-OPEN.EU Reloaded consortium, 2022,2024.
The content is Copyrighted and distributed under CC BY-NC Creative Commons Licence, free for Non-Commercial use.

en/iot-open/practical/hardware/sut/stm32/iot_1.1714076748.txt.gz · Last modified: 2024/04/25 20:25 by ktokarz
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0