ESPHome 2025.7.1
Loading...
Searching...
No Matches
ota_backend_arduino_esp32.cpp
Go to the documentation of this file.
1#ifdef USE_ESP32_FRAMEWORK_ARDUINO
3#include "esphome/core/log.h"
4
5#include "ota_backend.h"
7
8#include <Update.h>
9
10namespace esphome {
11namespace ota {
12
13static const char *const TAG = "ota.arduino_esp32";
14
15std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoESP32OTABackend>(); }
16
18 // Handle UPDATE_SIZE_UNKNOWN (0) which is used by web server OTA
19 // where the exact firmware size is unknown due to multipart encoding
20 if (image_size == 0) {
21 image_size = UPDATE_SIZE_UNKNOWN;
22 }
23 bool ret = Update.begin(image_size, U_FLASH);
24 if (ret) {
25 return OTA_RESPONSE_OK;
26 }
27
28 uint8_t error = Update.getError();
29 if (error == UPDATE_ERROR_SIZE)
31
32 ESP_LOGE(TAG, "Begin error: %d", error);
33
35}
36
38 Update.setMD5(md5);
39 this->md5_set_ = true;
40}
41
43 size_t written = Update.write(data, len);
44 if (written == len) {
45 return OTA_RESPONSE_OK;
46 }
47
48 uint8_t error = Update.getError();
49 ESP_LOGE(TAG, "Write error: %d", error);
50
52}
53
55 // Use strict validation (false) when MD5 is set, lenient validation (true) when no MD5
56 // This matches the behavior of the old web_server OTA implementation
57 if (Update.end(!this->md5_set_)) {
58 return OTA_RESPONSE_OK;
59 }
60
61 uint8_t error = Update.getError();
62 ESP_LOGE(TAG, "End error: %d", error);
63
65}
66
67void ArduinoESP32OTABackend::abort() { Update.abort(); }
68
69} // namespace ota
70} // namespace esphome
71
72#endif // USE_ESP32_FRAMEWORK_ARDUINO
void set_update_md5(const char *md5) override
OTAResponseTypes write(uint8_t *data, size_t len) override
OTAResponseTypes begin(size_t image_size) override
std::unique_ptr< ota::OTABackend > make_ota_backend()
@ OTA_RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE
Definition ota_backend.h:36
@ OTA_RESPONSE_ERROR_WRITING_FLASH
Definition ota_backend.h:30
@ OTA_RESPONSE_ERROR_UPDATE_END
Definition ota_backend.h:31
@ OTA_RESPONSE_ERROR_UNKNOWN
Definition ota_backend.h:40
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:229