ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
ota_backend_arduino_libretiny.cpp
Go to the documentation of this file.
1#ifdef USE_LIBRETINY
3#include "ota_backend.h"
4
6#include "esphome/core/log.h"
7
8#include <Update.h>
9
10namespace esphome::ota {
11
12static const char *const TAG = "ota.arduino_libretiny";
13
14std::unique_ptr<ArduinoLibreTinyOTABackend> make_ota_backend() { return make_unique<ArduinoLibreTinyOTABackend>(); }
15
17 // Handle UPDATE_SIZE_UNKNOWN (0) which is used by web server OTA
18 // where the exact firmware size is unknown due to multipart encoding
19 if (image_size == 0) {
20 image_size = UPDATE_SIZE_UNKNOWN;
21 }
22 bool ret = Update.begin(image_size, U_FLASH);
23 if (ret) {
24 return OTA_RESPONSE_OK;
25 }
26
27 uint8_t error = Update.getError();
28 if (error == UPDATE_ERROR_SIZE)
30
31 ESP_LOGE(TAG, "Begin error: %d", error);
32
34}
35
37 Update.setMD5(md5);
38 this->md5_set_ = true;
39}
40
42 size_t written = Update.write(data, len);
43 if (written == len) {
44 return OTA_RESPONSE_OK;
45 }
46
47 uint8_t error = Update.getError();
48 ESP_LOGE(TAG, "Write error: %d", error);
49
51}
52
54 // Use strict validation (false) when MD5 is set, lenient validation (true) when no MD5
55 // This matches the behavior of the old web_server OTA implementation
56 if (Update.end(!this->md5_set_)) {
57 return OTA_RESPONSE_OK;
58 }
59
60 uint8_t error = Update.getError();
61 ESP_LOGE(TAG, "End error: %d", error);
62
64}
65
66void ArduinoLibreTinyOTABackend::abort() { Update.abort(); }
67
68} // namespace esphome::ota
69#endif // USE_LIBRETINY
OTAResponseTypes write(uint8_t *data, size_t len)
@ 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:41
std::unique_ptr< ArduinoLibreTinyOTABackend > make_ota_backend()
std::string size_t len
Definition helpers.h:1045
int written
Definition helpers.h:1089