mirror of
https://github.com/esphome/esphome.git
synced 2026-06-04 17:43:05 +08:00
[OTA] Stage exact uploaded size for ESP8266 web OTA (gzip fix) (#14741)
This commit is contained in:
@@ -105,6 +105,7 @@ OTAResponseTypes ESP8266OTABackend::begin(size_t image_size) {
|
|||||||
|
|
||||||
this->current_address_ = this->start_address_;
|
this->current_address_ = this->start_address_;
|
||||||
this->image_size_ = image_size;
|
this->image_size_ = image_size;
|
||||||
|
this->bytes_received_ = 0;
|
||||||
this->buffer_len_ = 0;
|
this->buffer_len_ = 0;
|
||||||
this->md5_set_ = false;
|
this->md5_set_ = false;
|
||||||
|
|
||||||
@@ -140,6 +141,7 @@ OTAResponseTypes ESP8266OTABackend::write(uint8_t *data, size_t len) {
|
|||||||
size_t to_buffer = std::min(len - written, this->buffer_size_ - this->buffer_len_);
|
size_t to_buffer = std::min(len - written, this->buffer_size_ - this->buffer_len_);
|
||||||
memcpy(this->buffer_.get() + this->buffer_len_, data + written, to_buffer);
|
memcpy(this->buffer_.get() + this->buffer_len_, data + written, to_buffer);
|
||||||
this->buffer_len_ += to_buffer;
|
this->buffer_len_ += to_buffer;
|
||||||
|
this->bytes_received_ += to_buffer;
|
||||||
written += to_buffer;
|
written += to_buffer;
|
||||||
|
|
||||||
// If buffer is full, write to flash
|
// If buffer is full, write to flash
|
||||||
@@ -252,8 +254,8 @@ OTAResponseTypes ESP8266OTABackend::end() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate actual bytes written
|
// Calculate actual bytes written (exact uploaded size, excluding flash write padding)
|
||||||
size_t actual_size = this->current_address_ - this->start_address_;
|
size_t actual_size = this->bytes_received_;
|
||||||
|
|
||||||
// Check if any data was written
|
// Check if any data was written
|
||||||
if (actual_size == 0) {
|
if (actual_size == 0) {
|
||||||
@@ -304,6 +306,7 @@ void ESP8266OTABackend::abort() {
|
|||||||
this->buffer_.reset();
|
this->buffer_.reset();
|
||||||
this->buffer_len_ = 0;
|
this->buffer_len_ = 0;
|
||||||
this->image_size_ = 0;
|
this->image_size_ = 0;
|
||||||
|
this->bytes_received_ = 0;
|
||||||
esp8266::preferences_prevent_write(false);
|
esp8266::preferences_prevent_write(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ class ESP8266OTABackend final {
|
|||||||
uint32_t start_address_{0};
|
uint32_t start_address_{0};
|
||||||
uint32_t current_address_{0};
|
uint32_t current_address_{0};
|
||||||
size_t image_size_{0};
|
size_t image_size_{0};
|
||||||
|
size_t bytes_received_{0};
|
||||||
|
|
||||||
md5::MD5Digest md5_{};
|
md5::MD5Digest md5_{};
|
||||||
uint8_t expected_md5_[16]; // Fixed-size buffer for 128-bit (16-byte) MD5 digest
|
uint8_t expected_md5_[16]; // Fixed-size buffer for 128-bit (16-byte) MD5 digest
|
||||||
|
|||||||
Reference in New Issue
Block a user