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 12:25] – [Steps] pczekalski | en:iot-open:practical:hardware:sut:esp32:iot_2 [2024/04/21 11:39] (current) – pczekalski | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | <todo @pczekalski> | ||
====== IOT2: Reading IP address of the WiFi ===== | ====== 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, | 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, | ||
Line 22: | Line 21: | ||
==== Task to be implemented ==== | ==== Task to be implemented ==== | ||
- | Connect to the " | + | Connect to the " |
==== 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 clearly |
Line 38: | Line 37: | ||
=== Step 2 === | === Step 2 === | ||
- | Declare some constants, including AP SSID and passphrase: | + | Declare some constants, including AP SSID and passphrase |
<code c> | <code c> | ||
const char* ssid = " | const char* ssid = " | ||
const char* pass = " | const char* pass = " | ||
+ | IPAddress localIP; | ||
</ | </ | ||
- | Both '' | + | Both '' |
- | <todo @pczekalski> | + | |
=== Step 3 === | === Step 3 === | ||
- | Set your device in the STA mode: | + | Set your device in the STA mode and connect to the WiFi AP: |
<code c> | <code c> | ||
WiFi.mode(WIFI_STA); | 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 === | === Step 4 === | ||
Reading the IP as a '' | Reading the IP as a '' | ||
<code c> | <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 ==== | ==== Result validation ==== | ||
- | Using another node should | + | You should |
===== FAQ ===== | ===== FAQ ===== | ||
- | **Can I change MAC?**: Actually, yes, you can. It is not advised, however, because you may accidentally | + | **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.\\ |
- | <code c> | + | **Can I use a manually configured IP?**: Actually, you can, but we strongly discourage it. You may accidentally |
- | #include < | + | |
- | #include < | + | |
- | + | ||
- | uint8_t newMAC[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE}; //Array of bytes with new MAC | + | |
- | void setup() | + | |
- | { | + | |
- | WiFi.mode(WIFI_STA); | + | |
- | esp_wifi_set_mac(WIFI_IF_STA, | + | |
- | } | + | |
- | </ | + | |
<WRAP noprint> | <WRAP noprint> |