Fix reset on http_request without network connection (#2474)

* Fix reset problem when http_request is sent without network connection (#2501)

* Fix format
This commit is contained in:
niklasweber 2021-10-12 00:11:04 +02:00 committed by GitHub
parent 85461a752a
commit d7ad155885
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -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<HttpRequestResponseTrigger *> &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