mirror of
https://github.com/esphome/esphome.git
synced 2025-09-30 17:12:20 +01:00
Add OTA upload compression for ESP8266 (#2601)
This commit is contained in:
@@ -12,6 +12,7 @@ class OTABackend {
|
||||
virtual OTAResponseTypes write(uint8_t *data, size_t len) = 0;
|
||||
virtual OTAResponseTypes end() = 0;
|
||||
virtual void abort() = 0;
|
||||
virtual bool supports_compression() = 0;
|
||||
};
|
||||
|
||||
} // namespace ota
|
||||
|
@@ -15,6 +15,7 @@ class ArduinoESP32OTABackend : public OTABackend {
|
||||
OTAResponseTypes write(uint8_t *data, size_t len) override;
|
||||
OTAResponseTypes end() override;
|
||||
void abort() override;
|
||||
bool supports_compression() override { return false; }
|
||||
};
|
||||
|
||||
} // namespace ota
|
||||
|
@@ -16,6 +16,7 @@ class ArduinoESP8266OTABackend : public OTABackend {
|
||||
OTAResponseTypes write(uint8_t *data, size_t len) override;
|
||||
OTAResponseTypes end() override;
|
||||
void abort() override;
|
||||
bool supports_compression() override { return true; }
|
||||
};
|
||||
|
||||
} // namespace ota
|
||||
|
@@ -17,6 +17,7 @@ class IDFOTABackend : public OTABackend {
|
||||
OTAResponseTypes write(uint8_t *data, size_t len) override;
|
||||
OTAResponseTypes end() override;
|
||||
void abort() override;
|
||||
bool supports_compression() override { return false; }
|
||||
|
||||
private:
|
||||
esp_ota_handle_t update_handle_{0};
|
||||
|
@@ -104,6 +104,8 @@ void OTAComponent::loop() {
|
||||
}
|
||||
}
|
||||
|
||||
static const uint8_t FEATURE_SUPPORTS_COMPRESSION = 0x01;
|
||||
|
||||
void OTAComponent::handle_() {
|
||||
OTAResponseTypes error_code = OTA_RESPONSE_ERROR_UNKNOWN;
|
||||
bool update_started = false;
|
||||
@@ -154,6 +156,8 @@ void OTAComponent::handle_() {
|
||||
buf[1] = OTA_VERSION_1_0;
|
||||
this->writeall_(buf, 2);
|
||||
|
||||
backend = make_ota_backend();
|
||||
|
||||
// Read features - 1 byte
|
||||
if (!this->readall_(buf, 1)) {
|
||||
ESP_LOGW(TAG, "Reading features failed!");
|
||||
@@ -164,6 +168,10 @@ void OTAComponent::handle_() {
|
||||
|
||||
// Acknowledge header - 1 byte
|
||||
buf[0] = OTA_RESPONSE_HEADER_OK;
|
||||
if ((ota_features & FEATURE_SUPPORTS_COMPRESSION) != 0 && backend->supports_compression()) {
|
||||
buf[0] = OTA_RESPONSE_SUPPORTS_COMPRESSION;
|
||||
}
|
||||
|
||||
this->writeall_(buf, 1);
|
||||
|
||||
#ifdef USE_OTA_PASSWORD
|
||||
@@ -241,7 +249,6 @@ void OTAComponent::handle_() {
|
||||
}
|
||||
ESP_LOGV(TAG, "OTA size is %u bytes", ota_size);
|
||||
|
||||
backend = make_ota_backend();
|
||||
error_code = backend->begin(ota_size);
|
||||
if (error_code != OTA_RESPONSE_OK)
|
||||
goto error;
|
||||
|
@@ -19,6 +19,7 @@ enum OTAResponseTypes {
|
||||
OTA_RESPONSE_BIN_MD5_OK = 67,
|
||||
OTA_RESPONSE_RECEIVE_OK = 68,
|
||||
OTA_RESPONSE_UPDATE_END_OK = 69,
|
||||
OTA_RESPONSE_SUPPORTS_COMPRESSION = 70,
|
||||
|
||||
OTA_RESPONSE_ERROR_MAGIC = 128,
|
||||
OTA_RESPONSE_ERROR_UPDATE_PREPARE = 129,
|
||||
|
Reference in New Issue
Block a user