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_2 [2024/04/26 13:23] – [STM_IoT_2: Connecting to the WiFi Access Point and presenting IP] ktokarz | en:iot-open:practical:hardware:sut:stm32:iot_2 [2024/04/27 11:15] (current) – [Result validation] ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== 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 responsible for transmitting data packets between computers in the whole global web - the Internet. The same mechanism is used for addressing and transmitting packets among IP-capable IoT devices. The most popular local networks which support IP addressing are Ethernet and WiFi. Currently, the transition from traditional IPv4 to the new IPv6 version is occurring. Our laboratory supports IPv4. | ||
| + | \\ | ||
| + | The STM32WB55 SoC doesn' | ||
| + | \\ | ||
| + | ESP32 chip gets the IP address from the DHCP server after establishing the connection with the WiFi access point. In this scenario, we present how to connect to a WiFi network and read and display the IP address on an 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: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | |||
| + | ===== Suggested Readings and Knowledge Resources ===== | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | |||
| + | ===== Hands-on Lab Scenario ===== | ||
| + | |||
| + | ==== Task to be implemented ==== | ||
| + | Join the WiFi network. Present an IP address on the selected display. The commonly used format for IPv4 addresses requires 15 characters, so LCD having 16 characters is sufficient to present the address. The steps below show the starting part of the software. How to implement the full software please refer to the previous scenarios: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | < | ||
| + | The IPv4 addresses are usually expressed as four decimal numbers ranging from 0 to 255 separated by dots 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 === | ||
| + | The beginning of the code is the same as in the previous scenario, so make a copy of it: | ||
| + | * [[en: | ||
| + | |||
| + | 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); | ||
| + | </ | ||
| + | === 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 " | ||
| + | |||
| + | === Step 3 === | ||
| + | The command for receiving the IP address is " | ||
| + | <code c> | ||
| + | +CIPSTA: | ||
| + | +CIPSTA: | ||
| + | +CIPSTA: | ||
| + | </ | ||
| + | |||
| + | While LCD use we have to filter out unwanted elements of the response. We can do it by displaying the answer containing " | ||
| + | <code c> | ||
| + | if (response.startsWith(" | ||
| + | response.remove(0, | ||
| + | lcd.setCursor(0, | ||
| + | lcd.print(response); | ||
| + | } | ||
| + | </ | ||
| + | ==== Result validation ==== | ||
| + | You should be able to see the IP address of the ESP32-C3 module. | ||
| + | < | ||
| + | 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 ===== | ||
| + | **Can I change the IP address?**: Normally IP addresses are assigned by the server known as DHCP. In some situations, you can use static IP assigned manually in the station. 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> | ||
| + | {{: | ||
| + | </ | ||
| + | |||
| + | </ | ||