diff --git a/esphome/components/http_request/__init__.py b/esphome/components/http_request/__init__.py index 7dffdae27f..eea2f0d407 100644 --- a/esphome/components/http_request/__init__.py +++ b/esphome/components/http_request/__init__.py @@ -10,6 +10,7 @@ from esphome.const import ( CONF_METHOD, CONF_TRIGGER_ID, CONF_URL, + CONF_ESP8266_DISABLE_SSL_SUPPORT, ) from esphome.core import CORE, Lambda @@ -71,6 +72,9 @@ CONFIG_SCHEMA = cv.Schema( cv.GenerateID(): cv.declare_id(HttpRequestComponent), cv.Optional(CONF_USERAGENT, "ESPHome"): cv.string, cv.Optional(CONF_TIMEOUT, default="5s"): cv.positive_time_period_milliseconds, + cv.SplitDefault(CONF_ESP8266_DISABLE_SSL_SUPPORT, esp8266=False): cv.All( + cv.only_on_esp8266, cv.boolean + ), } ).extend(cv.COMPONENT_SCHEMA) @@ -98,6 +102,8 @@ async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) cg.add(var.set_timeout(config[CONF_TIMEOUT])) cg.add(var.set_useragent(config[CONF_USERAGENT])) + if CORE.is_esp8266 and not config[CONF_ESP8266_DISABLE_SSL_SUPPORT]: + cg.add_define("USE_HTTP_REQUEST_ESP8266_HTTPS") await cg.register_component(var, config) diff --git a/esphome/components/http_request/http_request.cpp b/esphome/components/http_request/http_request.cpp index 0d4e425147..3f5bf6da87 100644 --- a/esphome/components/http_request/http_request.cpp +++ b/esphome/components/http_request/http_request.cpp @@ -81,6 +81,7 @@ void HttpRequestComponent::send(const std::vector #ifdef ARDUINO_ARCH_ESP8266 std::shared_ptr HttpRequestComponent::get_wifi_client_() { +#ifdef USE_HTTP_REQUEST_ESP8266_HTTPS if (this->secure_) { if (this->wifi_client_secure_ == nullptr) { this->wifi_client_secure_ = std::make_shared(); @@ -89,6 +90,7 @@ std::shared_ptr HttpRequestComponent::get_wifi_client_() { } return this->wifi_client_secure_; } +#endif if (this->wifi_client_ == nullptr) { this->wifi_client_ = std::make_shared(); diff --git a/esphome/components/http_request/http_request.h b/esphome/components/http_request/http_request.h index 740a4580b4..fa29f8aa3a 100644 --- a/esphome/components/http_request/http_request.h +++ b/esphome/components/http_request/http_request.h @@ -3,6 +3,7 @@ #include "esphome/components/json/json_util.h" #include "esphome/core/automation.h" #include "esphome/core/component.h" +#include "esphome/core/defines.h" #include #include #include @@ -13,8 +14,10 @@ #endif #ifdef ARDUINO_ARCH_ESP8266 #include +#ifdef USE_HTTP_REQUEST_ESP8266_HTTPS #include #endif +#endif namespace esphome { namespace http_request { @@ -53,7 +56,9 @@ class HttpRequestComponent : public Component { std::list
headers_; #ifdef ARDUINO_ARCH_ESP8266 std::shared_ptr wifi_client_; +#ifdef USE_HTTP_REQUEST_ESP8266_HTTPS std::shared_ptr wifi_client_secure_; +#endif std::shared_ptr get_wifi_client_(); #endif }; diff --git a/esphome/const.py b/esphome/const.py index 92d18cde3a..a74068ab77 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -208,6 +208,7 @@ CONF_ENABLE_PIN = "enable_pin" CONF_ENABLE_TIME = "enable_time" CONF_ENERGY = "energy" CONF_ENTITY_ID = "entity_id" +CONF_ESP8266_DISABLE_SSL_SUPPORT = "esp8266_disable_ssl_support" CONF_ESP8266_RESTORE_FROM_FLASH = "esp8266_restore_from_flash" CONF_ESPHOME = "esphome" CONF_ETHERNET = "ethernet" diff --git a/esphome/core/defines.h b/esphome/core/defines.h index 45bb3b82a5..e3976d378e 100644 --- a/esphome/core/defines.h +++ b/esphome/core/defines.h @@ -20,6 +20,7 @@ #define USE_ESP8266_PREFERENCES_FLASH #define USE_FAN #define USE_HOMEASSISTANT_TIME +#define USE_HTTP_REQUEST_ESP8266_HTTPS #define USE_I2C_MULTIPLEXER #define USE_JSON #define USE_LIGHT