This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:iot-open:practical:hardware:sut:stm32:iot_2 [2024/04/26 08:54] – created ktokarz | en:iot-open:practical:hardware:sut:stm32:iot_2 [2024/04/27 08:15] (current) – [Result validation] ktokarz | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== STM_IoT_2: Connecting to the WiFi Access Point and presenting IP ===== | ====== STM_IoT_2: Connecting to the WiFi Access Point and presenting IP ===== | ||
- | Each computer connected to the Internet is identified with the IP address. IP abbreviation stands for Internet Protocol, which is responsilbe to transmit | + | Each computer connected to the Internet is identified with the IP address. IP abbreviation stands for Internet Protocol, which is responsible for transmitting |
\\ | \\ | ||
- | ESP32 chip gets the IP address from DHCP server after establishing the connection | + | The STM32WB55 SoC doesn' |
+ | \\ | ||
+ | ESP32 chip gets the IP address from the DHCP server after establishing the connection | ||
===== Prerequisites ===== | ===== Prerequisites ===== | ||
Line 21: | Line 23: | ||
==== Task to be implemented ==== | ==== Task to be implemented ==== | ||
- | Present | + | Join the WiFi network. |
+ | * [[en: | ||
+ | * [[en: | ||
< | < | ||
- | The MAC addresses | + | The IPv4 addresses are usually |
</ | </ | ||
==== Start ==== | ==== Start ==== | ||
Line 31: | Line 35: | ||
=== Step 1 === | === Step 1 === | ||
- | Include | + | The beginning of the code is the same as in the previous scenario, so make a copy of it: |
- | <code c> | + | * [[en: |
- | #include " | + | |
- | </ | + | |
- | Create objects of the LCD and Hardware Serial classes: | + | We will use the code template from [[en: |
- | <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> | <code c> | ||
WiFiSerial.println(" | WiFiSerial.println(" | ||
Line 73: | Line 51: | ||
delay(1000); | delay(1000); | ||
</ | </ | ||
+ | === Step 2 === | ||
+ | The procedure of connecting to the WiFi requires some steps. Below we present the AT commands only, your task is to implement the full code which sends the command and waits for the response for each command. | ||
+ | <code c> | ||
+ | // Test if module is available | ||
+ | " | ||
+ | |||
+ | // Reset the module | ||
+ | " | ||
+ | |||
+ | // Prevent from storing the WiFi join parameters in non-volatile memory | ||
+ | " | ||
+ | |||
+ | // Start module in station mode (which can join the access point) | ||
+ | " | ||
+ | |||
+ | // Join the access point. Use SSID and password. | ||
+ | " | ||
+ | |||
+ | // Get the IP address | ||
+ | " | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | Texts sent as part of the message are delimited with double quotation marks. In C++ we need to mark them with backslash characters inside the string constants. Examples above include these markings. | ||
+ | </ | ||
+ | Some explanation can be needed for the " | ||
+ | If we don't use the " | ||
+ | If we don't use the " | ||
- | The next command | + | === Step 3 === |
+ | The command | ||
<code c> | <code c> | ||
- | +CIPSTAMAC:"84:fc:e6:88:63:d1" | + | +CIPSTA:ip:"192.168.1.117" |
+ | +CIPSTA:gateway:" | ||
+ | +CIPSTA:netmask:" | ||
</ | </ | ||
- | 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 "AT" | + | While LCD use we have to filter out unwanted elements of the response. |
<code c> | <code c> | ||
- | if (response.startsWith(" | + | if (response.startsWith(" |
response.remove(0, | response.remove(0, | ||
lcd.setCursor(0, | lcd.setCursor(0, | ||
Line 88: | Line 97: | ||
</ | </ | ||
==== Result validation ==== | ==== Result validation ==== | ||
- | You should be able to see the MAC address of the ESP32-C3 module. | + | You should be able to see the IP address of the ESP32-C3 module. |
< | < | ||
- | Using another node should | + | Using another node ar even the same node another time can change the IP read. You can book another device and discover its IP. |
+ | </ | ||
+ | <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 ===== | ===== FAQ ===== | ||
- | **Can I change | + | **Can I change |
<WRAP noprint> | <WRAP noprint> |