This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:practical:hardware:sut:stm32:iot_1 [2024/04/25 23:19] – [Prerequisites] ktokarz | en:iot-open:practical:hardware:sut:stm32:iot_1 [2024/04/27 11:15] (current) – [Result validation] ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== 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' | ||
| + | \\ | ||
| + | ESP32 chip has built-in MAC. MAC can be used to identify devices, but note that it is not a " | ||
| + | |||
| + | ===== Prerequisites ===== | ||
| + | To implement this scenario, it is necessary to get familiar with at least one of the following scenarios first: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | |||
| + | ===== Suggested Readings and Knowledge Resources ===== | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | |||
| + | ===== 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. " | ||
| + | </ | ||
| + | ==== Start ==== | ||
| + | Check if you can see a full LCD in your video stream. Book a device and create a dummy Arduino file with '' | ||
| + | |||
| + | ==== Steps ==== | ||
| + | |||
| + | === Step 1 === | ||
| + | Include the LCD library in your source code: | ||
| + | <code c> | ||
| + | #include " | ||
| + | </ | ||
| + | |||
| + | Create objects of the LCD and Hardware Serial classes: | ||
| + | <code c> | ||
| + | // Serial port class and configuration (Constructor uses STM port numbering) | ||
| + | HardwareSerial WiFiSerial(RxD_PIN, | ||
| + | |||
| + | // LCD class | ||
| + | const int rs = PC5, en = PB11, d4 = PB12, d5 = PB13, d6 = PB14, d7 = PB15; | ||
| + | LiquidCrystal lcd(rs, en, d4, d5, d6, d7); | ||
| + | </ | ||
| + | |||
| + | Declare two variables with the strings to be compared with the responses from the WiFi module. | ||
| + | <code c> | ||
| + | String compOK; | ||
| + | String compERROR; | ||
| + | </ | ||
| + | === Step 2 === | ||
| + | In the Setup() function initialise the serial port, display, and strings. | ||
| + | <code c> | ||
| + | WiFiSerial.begin(115200); | ||
| + | lcd.begin(16, | ||
| + | compOK = " | ||
| + | compERROR = " | ||
| + | </ | ||
| + | |||
| + | We will use the code template from [[en: | ||
| + | <code c> | ||
| + | WiFiSerial.println(" | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(" | ||
| + | do { | ||
| + | response = WiFiSerial.readStringUntil(0x0A); | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(response); | ||
| + | } while (!(response.startsWith(compOK))); | ||
| + | |||
| + | delay(1000); | ||
| + | </ | ||
| + | |||
| + | The next command can be the " | ||
| + | <code c> | ||
| + | +CIPSTAMAC:" | ||
| + | </ | ||
| + | |||
| + | We can implement the part of displaying the MAC by repeating the block of the code similar to the one presented above with two modifications. Change the " | ||
| + | <code c> | ||
| + | if (response.startsWith(" | ||
| + | response.remove(0, | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(response); | ||
| + | } | ||
| + | </ | ||
| + | ==== Result validation ==== | ||
| + | You should be able to see the MAC address of the ESP32-C3 module. | ||
| + | < | ||
| + | Using another node should change the MAC read. Book another device and discover its MAC. | ||
| + | </ | ||
| + | <note info> | ||
| + | Because LCD can't properly display some non-visible characters the presented code sometimes shows additional, non-letter characters. It is out of the scope of this scenario to filter these characters out. We leave the task of making visual improvements to your invention. | ||
| + | </ | ||
| + | ===== 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. | ||
| + | |||
| + | <WRAP noprint> | ||
| + | ===== Project information ===== | ||
| + | {{: | ||
| + | This Intellectual Output was implemented under the Erasmus+ KA2.\\ | ||
| + | Project IOT-OPEN.EU Reloaded – Education-based strengthening of the European universities, | ||
| + | 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, | ||
| + | The content is Copyrighted and distributed under CC BY-NC [[https:// | ||
| + | <figure label> | ||
| + | {{: | ||
| + | </ | ||
| + | |||
| + | </ | ||