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 07:51] – [STM_IoT_1: Reading MAC address of the WiFi] ktokarz | en:iot-open:practical:hardware:sut:stm32:iot_1 [2024/04/27 08:15] (current) – [Result validation] ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== STM_IoT_1: Reading MAC address of the WiFi ===== | ====== 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' | 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 " | + | ESP32 chip has built-in MAC. MAC can be used to identify devices, but note that it is not a " |
| ===== Prerequisites ===== | ===== Prerequisites ===== | ||
| To implement this scenario, it is necessary to get familiar with at least one of the following scenarios first: | To implement this scenario, it is necessary to get familiar with at least one of the following scenarios first: | ||
| - | * [[en: | + | * [[en: |
| - | * [[en: | + | * [[en: |
| - | * [[en: | + | * [[en: |
| - | + | * [[en: | |
| - | A WiFi library is already included in the Arduino framework for ESP32, so there is no need to add it to the '' | + | |
| ===== Suggested Readings and Knowledge Resources ===== | ===== Suggested Readings and Knowledge Resources ===== | ||
| * [[en: | * [[en: | ||
| + | * [[en: | ||
| * [[en: | * [[en: | ||
| - | * [[en: | + | * [[en: |
| * [[en: | * [[en: | ||
| Line 21: | Line 21: | ||
| ==== Task to be implemented ==== | ==== Task to be implemented ==== | ||
| - | Present a MAC address on the selected display. The steps below present | + | Present a MAC address on the selected display. The steps below present the reading part and display |
| + | < | ||
| + | The MAC addresses usually are expressed | ||
| + | </ | ||
| ==== Start ==== | ==== Start ==== | ||
| Check if you can see a full LCD in your video stream. Book a device and create a dummy Arduino file with '' | Check if you can see a full LCD in your video stream. Book a device and create a dummy Arduino file with '' | ||
| - | |||
| ==== Steps ==== | ==== Steps ==== | ||
| === Step 1 === | === Step 1 === | ||
| - | Include the WiFi management | + | Include the LCD library in your source code: |
| <code c> | <code c> | ||
| - | # | + | # |
| </ | </ | ||
| - | The WiFi library automatically initialises a singleton class '' | ||
| + | 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 === | === Step 2 === | ||
| - | Reading | + | In the Setup() function initialise the serial port, display, and strings. |
| <code c> | <code c> | ||
| - | WiFi.macAddress(); | + | WiFiSerial.begin(115200); |
| + | lcd.begin(16, | ||
| + | compOK = " | ||
| + | compERROR = " | ||
| </ | </ | ||
| - | ==== Result validation ==== | + | We will use the code template from [[en: |
| - | Using another node should change the MAC read. Book another device and discover its MAC. | + | <code c> |
| + | WiFiSerial.println(" | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(" | ||
| + | do { | ||
| + | response | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(response); | ||
| + | } while (!(response.startsWith(compOK))); | ||
| - | ===== FAQ ===== | + | delay(1000); |
| - | **Can I change | + | </ |
| + | |||
| + | The next command can be the " | ||
| <code c> | <code c> | ||
| - | #include < | + | +CIPSTAMAC:" |
| - | # | + | </code> |
| - | uint8_t newMAC[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE}; // | + | 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 " |
| - | void setup() | + | <code c> |
| - | { | + | if (response.startsWith(" |
| - | | + | |
| - | | + | |
| + | 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> | <WRAP noprint> | ||