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 20:18] – [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 6: | Line 6: | ||
===== 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: | ||
Line 30: | Line 31: | ||
=== 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> |