From d7ad1558856a9e795117e038d21b5616d9d1d86a Mon Sep 17 00:00:00 2001 From: niklasweber Date: Tue, 12 Oct 2021 00:11:04 +0200 Subject: [PATCH] Fix reset on http_request without network connection (#2474) * Fix reset problem when http_request is sent without network connection (#2501) * Fix format --- esphome/components/http_request/http_request.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/esphome/components/http_request/http_request.cpp b/esphome/components/http_request/http_request.cpp index f88ee19e5c..309977a915 100644 --- a/esphome/components/http_request/http_request.cpp +++ b/esphome/components/http_request/http_request.cpp @@ -3,6 +3,7 @@ #include "http_request.h" #include "esphome/core/macros.h" #include "esphome/core/log.h" +#include "esphome/components/network/util.h" namespace esphome { namespace http_request { @@ -28,6 +29,13 @@ void HttpRequestComponent::set_url(std::string url) { } void HttpRequestComponent::send(const std::vector &response_triggers) { + if (!network::is_connected()) { + this->client_.end(); + this->status_set_warning(); + ESP_LOGW(TAG, "HTTP Request failed; Not connected to network"); + return; + } + bool begin_status = false; const String url = this->url_.c_str(); #ifdef USE_ESP32