Pokaż stronęPoprzednie wersjeOdnośnikiDo góry Ta strona jest tylko do odczytu. Możesz wyświetlić źródła tej strony ale nie możesz ich zmienić. ====== HTTP na ESP32 ====== \\ ===== Import ===== <code c> #include <HTTPClient.h> </code> \\ ===== GET request ===== <code c> if(WiFi.status()== WL_CONNECTED) { String url = "https://sases.pl"; HTTPClient httpClient; // Utworzenie instancji httpClient.begin(url.c_str()); int httpResponseCode = httpClient.GET(); if (httpResponseCode > 0) { if (httpResponseCode == 200) { String payload = httpClient.getString(); // String z zawartością URL } } httpClient.end(); // Zniszczenie instancji i zwolnienie zasobów } </code> \\ \\ ===== POST request ===== <code c> if(WiFi.status() == WL_CONNECTED) { String url = api_url + "/blinds/" + String(Blinds_Id[id]) + "/"; String payload = "{\"position\":0, \"runtime_up\": " + String(Blinds_Runtime_Up[id]) + ", \"runtime_down\": " + String(Blinds_Runtime_Down[id]) + "}"; HTTPClient httpClient; httpClient.begin(url); httpClient.addHeader("Content-Type", "application/json"); httpClient.addHeader("Authorization", "Bearer " + accessToken); int httpResponseCode = httpClient.POST(payload); if (httpResponseCode > 0) { if (httpResponseCode == 200) { String response = httpClient.getString(); // Serial.println(response); } else { Serial.print("API Error code: "); Serial.println(httpResponseCode); } } else { Serial.print("API Error on sending POST: "); Serial.println(httpResponseCode); } httpClient.end(); } </code> programowanie/esp32/http.txt ostatnio zmienione: 2024/10/09 20:12przez sases