From 1f3754684adccccc54a4795d8a685d13ba59e352 Mon Sep 17 00:00:00 2001 From: dentra Date: Wed, 24 Jul 2024 06:50:59 +0300 Subject: [PATCH] [http_request] Allow configure buffer size on ESP-IDF (#7125) Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> --- esphome/components/http_request/__init__.py | 11 +++++++++++ esphome/components/http_request/http_request_idf.cpp | 9 +++++++++ esphome/components/http_request/http_request_idf.h | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/esphome/components/http_request/__init__.py b/esphome/components/http_request/__init__.py index 161486fbb2..3ca97b9611 100644 --- a/esphome/components/http_request/__init__.py +++ b/esphome/components/http_request/__init__.py @@ -40,6 +40,8 @@ CONF_VERIFY_SSL = "verify_ssl" CONF_FOLLOW_REDIRECTS = "follow_redirects" CONF_REDIRECT_LIMIT = "redirect_limit" CONF_WATCHDOG_TIMEOUT = "watchdog_timeout" +CONF_BUFFER_SIZE_RX = "buffer_size_rx" +CONF_BUFFER_SIZE_TX = "buffer_size_tx" CONF_MAX_RESPONSE_BUFFER_SIZE = "max_response_buffer_size" CONF_ON_RESPONSE = "on_response" @@ -110,6 +112,12 @@ CONFIG_SCHEMA = cv.All( cv.positive_not_null_time_period, cv.positive_time_period_milliseconds, ), + cv.SplitDefault(CONF_BUFFER_SIZE_RX, esp32_idf=512): cv.All( + cv.uint16_t, cv.only_with_esp_idf + ), + cv.SplitDefault(CONF_BUFFER_SIZE_TX, esp32_idf=512): cv.All( + cv.uint16_t, cv.only_with_esp_idf + ), } ).extend(cv.COMPONENT_SCHEMA), cv.require_framework_version( @@ -137,6 +145,9 @@ async def to_code(config): 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_tx(config[CONF_BUFFER_SIZE_TX])) + esp32.add_idf_sdkconfig_option( "CONFIG_MBEDTLS_CERTIFICATE_BUNDLE", config.get(CONF_VERIFY_SSL), diff --git a/esphome/components/http_request/http_request_idf.cpp b/esphome/components/http_request/http_request_idf.cpp index 1f03b5f3bf..4fe5585723 100644 --- a/esphome/components/http_request/http_request_idf.cpp +++ b/esphome/components/http_request/http_request_idf.cpp @@ -18,6 +18,12 @@ namespace http_request { static const char *const TAG = "http_request.idf"; +void HttpRequestIDF::dump_config() { + HttpRequestComponent::dump_config(); + ESP_LOGCONFIG(TAG, " Buffer Size RX: %u", this->buffer_size_rx_); + ESP_LOGCONFIG(TAG, " Buffer Size TX: %u", this->buffer_size_tx_); +} + std::shared_ptr HttpRequestIDF::start(std::string url, std::string method, std::string body, std::list
headers) { if (!network::is_connected()) { @@ -63,6 +69,9 @@ std::shared_ptr HttpRequestIDF::start(std::string url, std::strin config.user_agent = this->useragent_; } + config.buffer_size = this->buffer_size_rx_; + config.buffer_size_tx = this->buffer_size_tx_; + const uint32_t start = millis(); watchdog::WatchdogManager wdm(this->get_watchdog_timeout()); diff --git a/esphome/components/http_request/http_request_idf.h b/esphome/components/http_request/http_request_idf.h index 79f850a636..431794924b 100644 --- a/esphome/components/http_request/http_request_idf.h +++ b/esphome/components/http_request/http_request_idf.h @@ -24,8 +24,18 @@ class HttpContainerIDF : public HttpContainer { class HttpRequestIDF : public HttpRequestComponent { public: + void dump_config() override; + std::shared_ptr start(std::string url, std::string method, std::string body, std::list
headers) override; + + void set_buffer_size_rx(uint16_t buffer_size_rx) { this->buffer_size_rx_ = buffer_size_rx; } + void set_buffer_size_tx(uint16_t buffer_size_tx) { this->buffer_size_tx_ = buffer_size_tx; } + + protected: + // if zero ESP-IDF will use DEFAULT_HTTP_BUF_SIZE + uint16_t buffer_size_rx_{}; + uint16_t buffer_size_tx_{}; }; } // namespace http_request