9 namespace http_request {
11 static const char *
const TAG =
"http_request";
14 ESP_LOGCONFIG(TAG,
"HTTP Request:");
15 ESP_LOGCONFIG(TAG,
" Timeout: %ums", this->
timeout_);
16 ESP_LOGCONFIG(TAG,
" User-Agent: %s", this->
useragent_);
22 this->
url_ = std::move(url);
23 this->
secure_ = this->
url_.compare(0, 6,
"https:") == 0;
37 ESP_LOGW(TAG,
"HTTP Request failed; Not connected to network");
41 bool begin_status =
false;
43 #if defined(USE_ESP32) || (defined(USE_ESP8266) && USE_ARDUINO_VERSION_CODE >= VERSION_CODE(2, 6, 0)) 44 #if defined(USE_ESP32) || USE_ARDUINO_VERSION_CODE >= VERSION_CODE(2, 7, 0) 46 this->
client_.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS);
48 this->
client_.setFollowRedirects(HTTPC_DISABLE_FOLLOW_REDIRECTS);
55 #if defined(USE_ESP32) 56 begin_status = this->
client_.begin(url);
57 #elif defined(USE_ESP8266) 64 ESP_LOGW(TAG,
"HTTP Request failed at the begin phase. Please check the configuration");
69 #if defined(USE_ESP32) 75 for (
const auto &header : this->
headers_) {
76 this->
client_.addHeader(header.name, header.value,
false,
true);
79 uint32_t start_time =
millis();
81 uint32_t duration =
millis() - start_time;
82 for (
auto *trigger : response_triggers)
83 trigger->process(http_code, duration);
86 ESP_LOGW(TAG,
"HTTP Request failed; URL: %s; Error: %s; Duration: %u ms", this->
url_.c_str(),
87 HTTPClient::errorToString(http_code).c_str(), duration);
92 if (http_code < 200 || http_code >= 300) {
93 ESP_LOGW(TAG,
"HTTP Request failed; URL: %s; Code: %d; Duration: %u ms", this->
url_.c_str(), http_code, duration);
99 ESP_LOGD(TAG,
"HTTP Request completed; URL: %s; Code: %d; Duration: %u ms", this->
url_.c_str(), http_code, duration);
104 #ifdef USE_HTTP_REQUEST_ESP8266_HTTPS 137 str = this->
client_.getString();
144 #endif // USE_ARDUINO
void status_set_warning(const char *message="unspecified")
bool is_connected()
Return whether the node is connected to the network (through wifi, eth, ...)
uint32_t IRAM_ATTR HOT millis()
std::shared_ptr< BearSSL::WiFiClientSecure > wifi_client_secure_
void status_clear_warning()
void send(const std::vector< HttpRequestResponseTrigger *> &response_triggers)
void set_url(std::string url)
std::shared_ptr< WiFiClient > get_wifi_client_()
const char * get_string()
void dump_config() override
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
std::list< Header > headers_
std::shared_ptr< WiFiClient > wifi_client_