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:esp32:iot_2 [2024/04/10 17:24] – [Steps] pczekalski | en:iot-open:practical:hardware:sut:esp32:iot_2 [2024/04/21 14:39] (current) – pczekalski | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== IOT2: Reading IP address of the WiFi ===== | ||
| + | On the networking level, IP devices are identified by MAC. In the case of our laboratory and network, you will obtain the IP address from the DHCP server integrated with the WiFi access point. To connect to the WiFi network, one needs to use credentials that are present in the general laboratory description, | ||
| + | |||
| + | In this scenario, you will learn how to set up your device in STA (client to the AP) mode, connect to the AP, and read the obtained IP address. This scenario does not contain a UI part; it is up to the developer to implement it using one of the scenarios presented below. | ||
| + | |||
| + | ===== Prerequisites ===== | ||
| + | To implement this scenario, it is necessary to get familiar with at least one of the following scenarios first: | ||
| + | * [[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 ===== | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | |||
| + | ===== Hands-on Lab Scenario ===== | ||
| + | |||
| + | ==== Task to be implemented ==== | ||
| + | Connect to the " | ||
| + | |||
| + | ==== Start ==== | ||
| + | Check if you can clearly see a full display (of your choice) in your video stream. Book a device and create a dummy Arduino file with '' | ||
| + | |||
| + | |||
| + | ==== Steps ==== | ||
| + | |||
| + | === Step 1 === | ||
| + | Include the WiFi management library in your source code: | ||
| + | <code c> | ||
| + | #include < | ||
| + | </ | ||
| + | The WiFi library automatically initialises a singleton class, '' | ||
| + | |||
| + | === Step 2 === | ||
| + | Declare some constants, including AP SSID and passphrase and a variable to store IP: | ||
| + | <code c> | ||
| + | const char* ssid = " | ||
| + | const char* pass = " | ||
| + | IPAddress localIP; | ||
| + | </ | ||
| + | |||
| + | Both '' | ||
| + | |||
| + | |||
| + | === Step 3 === | ||
| + | Set your device in the STA mode and connect to the WiFi AP: | ||
| + | <code c> | ||
| + | WiFi.mode(WIFI_STA); | ||
| + | WiFi.begin(ssid, | ||
| + | while (WiFi.status() != WL_CONNECTED) { | ||
| + | //Drop some info on display about connecting | ||
| + | delay(1000); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | The '' | ||
| + | * 0, '' | ||
| + | * 1, '' | ||
| + | * 2, '' | ||
| + | * 3, '' | ||
| + | * 4, '' | ||
| + | * 5, '' | ||
| + | * 6, '' | ||
| + | |||
| + | === Step 4 === | ||
| + | Reading the IP as a '' | ||
| + | <code c> | ||
| + | | ||
| + | </ | ||
| + | The '' | ||
| + | |||
| + | === Step 5 === | ||
| + | Explicitly disconnect from the WiFi AP to free resources: | ||
| + | <code c> | ||
| + | WiFi.disconnect(); | ||
| + | </ | ||
| + | |||
| + | Some useful WiFi functions are listed below: | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | ==== Result validation ==== | ||
| + | You should be able to connect to the WiFi and present the dynamically assigned IP address by the DHCP server. < | ||
| + | |||
| + | ===== FAQ ===== | ||
| + | **I set a hostname, but it does appear on the router level.**: There are many possible reasons; one is an active registration in the router (AP) that keeps an old IP address, so you need to wait until it expires; another reason is you have changed the hostname when you were connected to the AP.\\ | ||
| + | **Can I use a manually configured IP?**: Actually, you can, but we strongly discourage it. You may accidentally overlap this IP address with some other device, router, or infrastructure, | ||
| + | |||
| + | <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> | ||
| + | {{: | ||
| + | </ | ||
| + | |||
| + | </ | ||