Compare commits

...

10 Commits

Author SHA1 Message Date
J. Nick Koston
b4c0d89550 [logger] RP2040: Use write() with known length instead of println() 2025-12-21 12:20:50 -10:00
J. Nick Koston
1839f3f927 Merge branch 'dev' of https://github.com/esphome/esphome into dev 2025-12-21 12:12:44 -10:00
Steve
afbec0ba78 Merge branch 'dev' into dev 2025-12-21 12:46:44 +11:00
kabongsteve
97f311e84f Correct code update 2025-12-20 18:35:28 +11:00
kabongsteve
5528174590 Fix second location and compatibility issue 2025-12-20 18:01:15 +11:00
pre-commit-ci-lite[bot]
3ad6d860f0 [pre-commit.ci lite] apply automatic fixes 2025-12-20 05:54:51 +00:00
Steve
51ea938eea Merge branch 'dev' into dev 2025-12-20 16:53:01 +11:00
kabongsteve
2a1c24ba15 Update code after code review 2025-12-20 16:52:31 +11:00
kabongsteve
2eff8850c5 Fix clang-tidy issue 2025-12-17 16:25:03 +11:00
kabongsteve
26c4d749df Fix issue when esp_http_client_fetch_headers returns error 2025-12-17 15:50:41 +11:00
3 changed files with 45 additions and 19 deletions

View File

@@ -152,14 +152,26 @@ std::shared_ptr<HttpContainer> HttpRequestIDF::perform(const std::string &url, c
} }
container->feed_wdt(); container->feed_wdt();
container->content_length = esp_http_client_fetch_headers(client); int64_t result = esp_http_client_fetch_headers(client);
container->feed_wdt(); if (result < 0) {
container->status_code = esp_http_client_get_status_code(client); if (result == -ESP_ERR_HTTP_EAGAIN) {
container->feed_wdt(); container->status_code = ESP_ERR_HTTP_EAGAIN;
container->set_response_headers(user_data.response_headers); } else {
container->duration_ms = millis() - start; this->status_momentary_error("failed", 1000);
if (is_success(container->status_code)) { ESP_LOGE(TAG, "HTTP Request failed: %s", esp_err_to_name(result));
return container; esp_http_client_cleanup(client);
return nullptr;
}
} else {
container->content_length = result;
container->feed_wdt();
container->status_code = esp_http_client_get_status_code(client);
container->feed_wdt();
container->set_response_headers(user_data.response_headers);
container->duration_ms = millis() - start;
if (is_success(container->status_code)) {
return container;
}
} }
if (this->follow_redirects_) { if (this->follow_redirects_) {
@@ -187,15 +199,26 @@ std::shared_ptr<HttpContainer> HttpRequestIDF::perform(const std::string &url, c
} }
container->feed_wdt(); container->feed_wdt();
container->content_length = esp_http_client_fetch_headers(client); result = esp_http_client_fetch_headers(client);
container->feed_wdt(); if (result < 0) {
container->status_code = esp_http_client_get_status_code(client); if (result == -ESP_ERR_HTTP_EAGAIN) {
container->feed_wdt(); container->status_code = ESP_ERR_HTTP_EAGAIN;
container->duration_ms = millis() - start; } else {
if (is_success(container->status_code)) { this->status_momentary_error("failed", 1000);
return container; ESP_LOGE(TAG, "HTTP Request failed: %s", esp_err_to_name(result));
esp_http_client_cleanup(client);
return nullptr;
}
} else {
container->content_length = result;
container->feed_wdt();
container->status_code = esp_http_client_get_status_code(client);
container->feed_wdt();
container->duration_ms = millis() - start;
if (is_success(container->status_code)) {
return container;
}
} }
num_redirects--; num_redirects--;
} }

View File

@@ -118,11 +118,11 @@ static constexpr uint16_t MAX_HEADER_SIZE = 128;
static constexpr size_t MAX_POINTER_REPRESENTATION = 2 + sizeof(void *) * 2 + 1; static constexpr size_t MAX_POINTER_REPRESENTATION = 2 + sizeof(void *) * 2 + 1;
// Platform-specific: does write_msg_ add its own newline? // Platform-specific: does write_msg_ add its own newline?
// false: Caller must add newline to buffer before calling write_msg_ (ESP32, ESP8266, LibreTiny) // false: Caller must add newline to buffer before calling write_msg_ (ESP32, ESP8266, RP2040, LibreTiny)
// Allows single write call with newline included for efficiency // Allows single write call with newline included for efficiency
// true: write_msg_ adds newline itself via puts()/println() (other platforms) // true: write_msg_ adds newline itself via puts()/println() (other platforms)
// Newline should NOT be added to buffer // Newline should NOT be added to buffer
#if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_LIBRETINY) #if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040) || defined(USE_LIBRETINY)
static constexpr bool WRITE_MSG_ADDS_NEWLINE = false; static constexpr bool WRITE_MSG_ADDS_NEWLINE = false;
#else #else
static constexpr bool WRITE_MSG_ADDS_NEWLINE = true; static constexpr bool WRITE_MSG_ADDS_NEWLINE = true;

View File

@@ -27,7 +27,10 @@ void Logger::pre_setup() {
ESP_LOGI(TAG, "Log initialized"); ESP_LOGI(TAG, "Log initialized");
} }
void HOT Logger::write_msg_(const char *msg, size_t) { this->hw_serial_->println(msg); } void HOT Logger::write_msg_(const char *msg, size_t len) {
// Single write with newline already in buffer (added by caller)
this->hw_serial_->write(msg, len);
}
const LogString *Logger::get_uart_selection_() { const LogString *Logger::get_uart_selection_() {
switch (this->uart_) { switch (this->uart_) {