8#include "esp_http_client.h"
9#include "esp_idf_version.h"
10#include "esp_system.h"
47 virtual bool begin(
const char*
urlStr,
const char* acceptMime =
"",
49 const char* reqData =
"") {
58 if (
ssid !=
nullptr) {
65 Serial.print(
"Waiting for connection ");
79 memset(&cntry, 0,
sizeof(wifi_country_t));
80 esp_wifi_get_country(&cntry);
82 strncpy(text, cntry.cc, 3);
83 LOGI(
"wifi country: %s", text);
86 esp_http_client_config_t http_config;
87 memset(&http_config, 0,
sizeof(http_config));
93 http_config.user_data =
this;
96 http_config.cert_pem = (
const char*)
pem_cert;
106 http_config.method = HTTP_METHOD_GET;
109 http_config.method = HTTP_METHOD_POST;
112 http_config.method = HTTP_METHOD_PUT;
115 http_config.method = HTTP_METHOD_DELETE;
118 LOGE(
"Unsupported action: %d", action);
131 for (
auto it = lines.
begin(); it != lines.
end(); ++it) {
133 esp_http_client_set_header(
client_handle, (*it)->key.c_str(),
134 (*it)->value.c_str());
140 LOGE(
"esp_http_client_open");
146 int status_code = esp_http_client_get_status_code(
client_handle);
155 return status_code == 200;
158 virtual void end()
override {
179 size_t write(
const uint8_t* data,
size_t len)
override {
181 int written = esp_http_client_write(
client_handle, (
const char*)data, len);
183 LOGE(
"esp_http_client_write: %d", written);
191 int read = esp_http_client_read(
client_handle, (
char*)data, len);
193 LOGE(
"esp_http_client_read: %d", read);
213 int len = strlen(cert);
214 setCACert((
const uint8_t*)cert, len + 1);
265 assert(cert[len - 1] == 0);
269 switch (evt->event_id) {
270 case HTTP_EVENT_ERROR:
271 LOGI(
"HTTP_EVENT_ERROR");
273 case HTTP_EVENT_ON_CONNECTED:
274 LOGD(
"HTTP_EVENT_ON_CONNECTED");
276 case HTTP_EVENT_HEADER_SENT:
277 LOGD(
"HTTP_EVENT_HEADER_SENT");
279 case HTTP_EVENT_ON_HEADER:
280 LOGI(
"HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key,
286 case HTTP_EVENT_ON_DATA:
287 LOGD(
"HTTP_EVENT_ON_DATA, len=%d", evt->data_len);
289 case HTTP_EVENT_ON_FINISH:
290 LOGI(
"HTTP_EVENT_ON_FINISH");
292 case HTTP_EVENT_DISCONNECTED:
293 LOGI(
"HTTP_EVENT_DISCONNECTED");
295#if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(5, 3, 7)
296 case HTTP_EVENT_REDIRECT:
297 LOGI(
"HTTP_EVENT_REDIRECT");
307#if defined(USE_CONCURRENCY)
static HardwareSerial Serial
Definition Arduino.h:179
#define TRACED()
Definition AudioLoggerIDF.h:31
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGD(...)
Definition AudioLoggerIDF.h:27
#define LOGE(...)
Definition AudioLoggerIDF.h:30
MethodID
supported http methods
Definition HttpTypes.h:3
@ GET
Definition HttpTypes.h:5
@ POST
Definition HttpTypes.h:7
@ DELETE
Definition HttpTypes.h:9
@ PUT
Definition HttpTypes.h:8
#define DEFAULT_BUFFER_SIZE
Definition avr.h:20
#define assert(T)
Definition avr.h:10
int _timeout
Definition Arduino.h:133
#define URL_CLIENT_TIMEOUT
Definition esp8266.h:23
class audio_tools::WiFiESP32 IDF_WIFI