Różnice
Różnice między wybraną wersją a wersją aktualną.
| Nowa wersja | Poprzednia wersja | ||
| programowanie:esp32:wifi [2024/08/09 10:55] – utworzono sases | programowanie:esp32:wifi [2024/09/08 12:11] (aktualna) – sases | ||
|---|---|---|---|
| Linia 1: | Linia 1: | ||
| - | ====== WiFi na ESP 32 ====== | + | ====== WiFi na ESP32 ====== |
| Obsługa WiFi na ESP32.\\ | Obsługa WiFi na ESP32.\\ | ||
| + | \\ | ||
| \\ | \\ | ||
| - | === Kod === | + | ===== Deklaracje ===== |
| <code c> | <code c> | ||
| + | #include " | ||
| #include < | #include < | ||
| - | const String WiFi_SSID = " | + | const String WiFi_SSID = " |
| - | const String WiFi_password = " | + | const String WiFi_password = " |
| - | String WiFi_IP = ""; | + | String WiFi_IP = ""; |
| WiFiClient wifiClient; | WiFiClient wifiClient; | ||
| void connectWiFi(); | void connectWiFi(); | ||
| + | </ | ||
| + | \\ | ||
| + | \\ | ||
| + | ===== Połączenie podczas uruchomienia ===== | ||
| + | |||
| + | <code c> | ||
| void setup() | void setup() | ||
| { | { | ||
| connectWiFi(); | connectWiFi(); | ||
| } | } | ||
| + | </ | ||
| + | \\ | ||
| + | \\ | ||
| + | ===== Ponowne łączenie w przypadku rozłączenia ===== | ||
| + | |||
| + | <code c> | ||
| void loop() | void loop() | ||
| { | { | ||
| Linia 26: | Linia 40: | ||
| vTaskDelay(pdMS_TO_TICKS(10)); | vTaskDelay(pdMS_TO_TICKS(10)); | ||
| } | } | ||
| + | </ | ||
| + | \\ | ||
| + | \\ | ||
| + | ===== Funkcja ===== | ||
| + | |||
| + | <code c> | ||
| void connectWiFi() | void connectWiFi() | ||
| - | { // ustanawianie połączenia WiFi | + | { |
| digitalWrite(BUILT_LED, | digitalWrite(BUILT_LED, | ||
| WiFi.hostname(myHostname); | WiFi.hostname(myHostname); | ||
| Linia 44: | Linia 64: | ||
| } | } | ||
| ++attempt; | ++attempt; | ||
| - | vTaskDelay(pdMS_TO_TICKS(200)); | + | vTaskDelay(pdMS_TO_TICKS(500)); |
| wl_status_t status = WiFi.status(); | wl_status_t status = WiFi.status(); | ||
| Linia 67: | Linia 87: | ||
| </ | </ | ||
| \\ | \\ | ||
| - | === Kody błędów === | + | [[inne: |
| + | \\ | ||
| + | \\ | ||
| + | |||
| + | ===== Kody błędów ===== | ||
| ^ WL_NO_SHIELD | 255 | assigned when no WiFi shield is present | | ^ WL_NO_SHIELD | 255 | assigned when no WiFi shield is present | | ||
| ^ WL_IDLE_STATUS | 0 | it is a temporary status assigned when WiFi.begin() is called and remains active until the number of attempts expires (resulting in WL_CONNECT_FAILED) or a connection is established (resulting in WL_CONNECTED) | | ^ WL_IDLE_STATUS | 0 | it is a temporary status assigned when WiFi.begin() is called and remains active until the number of attempts expires (resulting in WL_CONNECT_FAILED) or a connection is established (resulting in WL_CONNECTED) | | ||