mirror of
https://github.com/esphome/esphome.git
synced 2026-01-10 12:10:48 -07:00
[http_request] Use ESP-IDF for ESP32 Arduino (#12428)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -69,9 +69,6 @@ def validate_url(value):
|
|||||||
def validate_ssl_verification(config):
|
def validate_ssl_verification(config):
|
||||||
error_message = ""
|
error_message = ""
|
||||||
|
|
||||||
if CORE.is_esp32 and not CORE.using_esp_idf and config[CONF_VERIFY_SSL]:
|
|
||||||
error_message = "ESPHome supports certificate verification only via ESP-IDF"
|
|
||||||
|
|
||||||
if CORE.is_rp2040 and config[CONF_VERIFY_SSL]:
|
if CORE.is_rp2040 and config[CONF_VERIFY_SSL]:
|
||||||
error_message = "ESPHome does not support certificate verification on RP2040"
|
error_message = "ESPHome does not support certificate verification on RP2040"
|
||||||
|
|
||||||
@@ -93,9 +90,9 @@ def validate_ssl_verification(config):
|
|||||||
def _declare_request_class(value):
|
def _declare_request_class(value):
|
||||||
if CORE.is_host:
|
if CORE.is_host:
|
||||||
return cv.declare_id(HttpRequestHost)(value)
|
return cv.declare_id(HttpRequestHost)(value)
|
||||||
if CORE.using_esp_idf:
|
if CORE.is_esp32:
|
||||||
return cv.declare_id(HttpRequestIDF)(value)
|
return cv.declare_id(HttpRequestIDF)(value)
|
||||||
if CORE.is_esp8266 or CORE.is_esp32 or CORE.is_rp2040:
|
if CORE.is_esp8266 or CORE.is_rp2040:
|
||||||
return cv.declare_id(HttpRequestArduino)(value)
|
return cv.declare_id(HttpRequestArduino)(value)
|
||||||
return NotImplementedError
|
return NotImplementedError
|
||||||
|
|
||||||
@@ -121,11 +118,11 @@ CONFIG_SCHEMA = cv.All(
|
|||||||
cv.positive_not_null_time_period,
|
cv.positive_not_null_time_period,
|
||||||
cv.positive_time_period_milliseconds,
|
cv.positive_time_period_milliseconds,
|
||||||
),
|
),
|
||||||
cv.SplitDefault(CONF_BUFFER_SIZE_RX, esp32_idf=512): cv.All(
|
cv.SplitDefault(CONF_BUFFER_SIZE_RX, esp32=512): cv.All(
|
||||||
cv.uint16_t, cv.only_with_esp_idf
|
cv.uint16_t, cv.only_on_esp32
|
||||||
),
|
),
|
||||||
cv.SplitDefault(CONF_BUFFER_SIZE_TX, esp32_idf=512): cv.All(
|
cv.SplitDefault(CONF_BUFFER_SIZE_TX, esp32=512): cv.All(
|
||||||
cv.uint16_t, cv.only_with_esp_idf
|
cv.uint16_t, cv.only_on_esp32
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_CA_CERTIFICATE_PATH): cv.All(
|
cv.Optional(CONF_CA_CERTIFICATE_PATH): cv.All(
|
||||||
cv.file_,
|
cv.file_,
|
||||||
@@ -158,25 +155,20 @@ async def to_code(config):
|
|||||||
cg.add(var.set_watchdog_timeout(timeout_ms))
|
cg.add(var.set_watchdog_timeout(timeout_ms))
|
||||||
|
|
||||||
if CORE.is_esp32:
|
if CORE.is_esp32:
|
||||||
if CORE.using_esp_idf:
|
cg.add(var.set_buffer_size_rx(config[CONF_BUFFER_SIZE_RX]))
|
||||||
cg.add(var.set_buffer_size_rx(config[CONF_BUFFER_SIZE_RX]))
|
cg.add(var.set_buffer_size_tx(config[CONF_BUFFER_SIZE_TX]))
|
||||||
cg.add(var.set_buffer_size_tx(config[CONF_BUFFER_SIZE_TX]))
|
|
||||||
|
|
||||||
esp32.add_idf_sdkconfig_option(
|
if config.get(CONF_VERIFY_SSL):
|
||||||
"CONFIG_MBEDTLS_CERTIFICATE_BUNDLE",
|
esp32.add_idf_sdkconfig_option("CONFIG_MBEDTLS_CERTIFICATE_BUNDLE", True)
|
||||||
config.get(CONF_VERIFY_SSL),
|
|
||||||
)
|
esp32.add_idf_sdkconfig_option(
|
||||||
esp32.add_idf_sdkconfig_option(
|
"CONFIG_ESP_TLS_INSECURE",
|
||||||
"CONFIG_ESP_TLS_INSECURE",
|
not config.get(CONF_VERIFY_SSL),
|
||||||
not config.get(CONF_VERIFY_SSL),
|
)
|
||||||
)
|
esp32.add_idf_sdkconfig_option(
|
||||||
esp32.add_idf_sdkconfig_option(
|
"CONFIG_ESP_TLS_SKIP_SERVER_CERT_VERIFY",
|
||||||
"CONFIG_ESP_TLS_SKIP_SERVER_CERT_VERIFY",
|
not config.get(CONF_VERIFY_SSL),
|
||||||
not config.get(CONF_VERIFY_SSL),
|
)
|
||||||
)
|
|
||||||
else:
|
|
||||||
cg.add_library("NetworkClientSecure", None)
|
|
||||||
cg.add_library("HTTPClient", None)
|
|
||||||
if CORE.is_esp8266:
|
if CORE.is_esp8266:
|
||||||
cg.add_library("ESP8266HTTPClient", None)
|
cg.add_library("ESP8266HTTPClient", None)
|
||||||
if CORE.is_rp2040 and CORE.using_arduino:
|
if CORE.is_rp2040 and CORE.using_arduino:
|
||||||
@@ -327,13 +319,15 @@ FILTER_SOURCE_FILES = filter_source_files_from_platform(
|
|||||||
{
|
{
|
||||||
"http_request_host.cpp": {PlatformFramework.HOST_NATIVE},
|
"http_request_host.cpp": {PlatformFramework.HOST_NATIVE},
|
||||||
"http_request_arduino.cpp": {
|
"http_request_arduino.cpp": {
|
||||||
PlatformFramework.ESP32_ARDUINO,
|
|
||||||
PlatformFramework.ESP8266_ARDUINO,
|
PlatformFramework.ESP8266_ARDUINO,
|
||||||
PlatformFramework.RP2040_ARDUINO,
|
PlatformFramework.RP2040_ARDUINO,
|
||||||
PlatformFramework.BK72XX_ARDUINO,
|
PlatformFramework.BK72XX_ARDUINO,
|
||||||
PlatformFramework.RTL87XX_ARDUINO,
|
PlatformFramework.RTL87XX_ARDUINO,
|
||||||
PlatformFramework.LN882X_ARDUINO,
|
PlatformFramework.LN882X_ARDUINO,
|
||||||
},
|
},
|
||||||
"http_request_idf.cpp": {PlatformFramework.ESP32_IDF},
|
"http_request_idf.cpp": {
|
||||||
|
PlatformFramework.ESP32_ARDUINO,
|
||||||
|
PlatformFramework.ESP32_IDF,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,8 +4,7 @@
|
|||||||
|
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome::http_request {
|
||||||
namespace http_request {
|
|
||||||
|
|
||||||
static const char *const TAG = "http_request";
|
static const char *const TAG = "http_request";
|
||||||
|
|
||||||
@@ -42,5 +41,4 @@ std::string HttpContainer::get_response_header(const std::string &header_name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace http_request
|
} // namespace esphome::http_request
|
||||||
} // namespace esphome
|
|
||||||
|
|||||||
@@ -15,8 +15,7 @@
|
|||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome::http_request {
|
||||||
namespace http_request {
|
|
||||||
|
|
||||||
struct Header {
|
struct Header {
|
||||||
std::string name;
|
std::string name;
|
||||||
@@ -305,5 +304,4 @@ template<typename... Ts> class HttpRequestSendAction : public Action<Ts...> {
|
|||||||
size_t max_response_buffer_size_{SIZE_MAX};
|
size_t max_response_buffer_size_{SIZE_MAX};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace http_request
|
} // namespace esphome::http_request
|
||||||
} // namespace esphome
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "http_request_arduino.h"
|
#include "http_request_arduino.h"
|
||||||
|
|
||||||
#ifdef USE_ARDUINO
|
#if defined(USE_ARDUINO) && !defined(USE_ESP32)
|
||||||
|
|
||||||
#include "esphome/components/network/util.h"
|
#include "esphome/components/network/util.h"
|
||||||
#include "esphome/components/watchdog/watchdog.h"
|
#include "esphome/components/watchdog/watchdog.h"
|
||||||
@@ -9,8 +9,7 @@
|
|||||||
#include "esphome/core/defines.h"
|
#include "esphome/core/defines.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome::http_request {
|
||||||
namespace http_request {
|
|
||||||
|
|
||||||
static const char *const TAG = "http_request.arduino";
|
static const char *const TAG = "http_request.arduino";
|
||||||
|
|
||||||
@@ -75,8 +74,6 @@ std::shared_ptr<HttpContainer> HttpRequestArduino::perform(const std::string &ur
|
|||||||
container->client_.setInsecure();
|
container->client_.setInsecure();
|
||||||
}
|
}
|
||||||
bool status = container->client_.begin(url.c_str());
|
bool status = container->client_.begin(url.c_str());
|
||||||
#elif defined(USE_ESP32)
|
|
||||||
bool status = container->client_.begin(url.c_str());
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
App.feed_wdt();
|
App.feed_wdt();
|
||||||
@@ -90,9 +87,6 @@ std::shared_ptr<HttpContainer> HttpRequestArduino::perform(const std::string &ur
|
|||||||
|
|
||||||
container->client_.setReuse(true);
|
container->client_.setReuse(true);
|
||||||
container->client_.setTimeout(this->timeout_);
|
container->client_.setTimeout(this->timeout_);
|
||||||
#if defined(USE_ESP32)
|
|
||||||
container->client_.setConnectTimeout(this->timeout_);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (this->useragent_ != nullptr) {
|
if (this->useragent_ != nullptr) {
|
||||||
container->client_.setUserAgent(this->useragent_);
|
container->client_.setUserAgent(this->useragent_);
|
||||||
@@ -177,7 +171,6 @@ void HttpContainerArduino::end() {
|
|||||||
this->client_.end();
|
this->client_.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace http_request
|
} // namespace esphome::http_request
|
||||||
} // namespace esphome
|
|
||||||
|
|
||||||
#endif // USE_ARDUINO
|
#endif // USE_ARDUINO && !USE_ESP32
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
#include "http_request.h"
|
#include "http_request.h"
|
||||||
|
|
||||||
#ifdef USE_ARDUINO
|
#if defined(USE_ARDUINO) && !defined(USE_ESP32)
|
||||||
|
|
||||||
#if defined(USE_ESP32) || defined(USE_RP2040)
|
#if defined(USE_RP2040)
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -15,8 +15,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome::http_request {
|
||||||
namespace http_request {
|
|
||||||
|
|
||||||
class HttpRequestArduino;
|
class HttpRequestArduino;
|
||||||
class HttpContainerArduino : public HttpContainer {
|
class HttpContainerArduino : public HttpContainer {
|
||||||
@@ -36,7 +35,6 @@ class HttpRequestArduino : public HttpRequestComponent {
|
|||||||
const std::set<std::string> &collect_headers) override;
|
const std::set<std::string> &collect_headers) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace http_request
|
} // namespace esphome::http_request
|
||||||
} // namespace esphome
|
|
||||||
|
|
||||||
#endif // USE_ARDUINO
|
#endif // USE_ARDUINO && !USE_ESP32
|
||||||
|
|||||||
@@ -12,8 +12,7 @@
|
|||||||
#include "esphome/core/application.h"
|
#include "esphome/core/application.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome::http_request {
|
||||||
namespace http_request {
|
|
||||||
|
|
||||||
static const char *const TAG = "http_request.host";
|
static const char *const TAG = "http_request.host";
|
||||||
|
|
||||||
@@ -139,7 +138,6 @@ void HttpContainerHost::end() {
|
|||||||
this->bytes_read_ = 0;
|
this->bytes_read_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace http_request
|
} // namespace esphome::http_request
|
||||||
} // namespace esphome
|
|
||||||
|
|
||||||
#endif // USE_HOST
|
#endif // USE_HOST
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#ifdef USE_HOST
|
#ifdef USE_HOST
|
||||||
#include "http_request.h"
|
#include "http_request.h"
|
||||||
namespace esphome {
|
|
||||||
namespace http_request {
|
namespace esphome::http_request {
|
||||||
|
|
||||||
class HttpRequestHost;
|
class HttpRequestHost;
|
||||||
class HttpContainerHost : public HttpContainer {
|
class HttpContainerHost : public HttpContainer {
|
||||||
@@ -27,7 +27,6 @@ class HttpRequestHost : public HttpRequestComponent {
|
|||||||
const char *ca_path_{};
|
const char *ca_path_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace http_request
|
} // namespace esphome::http_request
|
||||||
} // namespace esphome
|
|
||||||
|
|
||||||
#endif // USE_HOST
|
#endif // USE_HOST
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "http_request_idf.h"
|
#include "http_request_idf.h"
|
||||||
|
|
||||||
#ifdef USE_ESP_IDF
|
#ifdef USE_ESP32
|
||||||
|
|
||||||
#include "esphome/components/network/util.h"
|
#include "esphome/components/network/util.h"
|
||||||
#include "esphome/components/watchdog/watchdog.h"
|
#include "esphome/components/watchdog/watchdog.h"
|
||||||
@@ -14,8 +14,7 @@
|
|||||||
|
|
||||||
#include "esp_task_wdt.h"
|
#include "esp_task_wdt.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome::http_request {
|
||||||
namespace http_request {
|
|
||||||
|
|
||||||
static const char *const TAG = "http_request.idf";
|
static const char *const TAG = "http_request.idf";
|
||||||
|
|
||||||
@@ -245,7 +244,6 @@ void HttpContainerIDF::feed_wdt() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace http_request
|
} // namespace esphome::http_request
|
||||||
} // namespace esphome
|
|
||||||
|
|
||||||
#endif // USE_ESP_IDF
|
#endif // USE_ESP32
|
||||||
|
|||||||
@@ -2,15 +2,14 @@
|
|||||||
|
|
||||||
#include "http_request.h"
|
#include "http_request.h"
|
||||||
|
|
||||||
#ifdef USE_ESP_IDF
|
#ifdef USE_ESP32
|
||||||
|
|
||||||
#include <esp_event.h>
|
#include <esp_event.h>
|
||||||
#include <esp_http_client.h>
|
#include <esp_http_client.h>
|
||||||
#include <esp_netif.h>
|
#include <esp_netif.h>
|
||||||
#include <esp_tls.h>
|
#include <esp_tls.h>
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome::http_request {
|
||||||
namespace http_request {
|
|
||||||
|
|
||||||
class HttpContainerIDF : public HttpContainer {
|
class HttpContainerIDF : public HttpContainer {
|
||||||
public:
|
public:
|
||||||
@@ -48,7 +47,6 @@ class HttpRequestIDF : public HttpRequestComponent {
|
|||||||
static esp_err_t http_event_handler(esp_http_client_event_t *evt);
|
static esp_err_t http_event_handler(esp_http_client_event_t *evt);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace http_request
|
} // namespace esphome::http_request
|
||||||
} // namespace esphome
|
|
||||||
|
|
||||||
#endif // USE_ESP_IDF
|
#endif // USE_ESP32
|
||||||
|
|||||||
Reference in New Issue
Block a user