ESPHome  2024.11.1
ota_backend_arduino_esp8266.cpp
Go to the documentation of this file.
1 #ifdef USE_ARDUINO
2 #ifdef USE_ESP8266
4 #include "ota_backend.h"
5 
7 #include "esphome/core/defines.h"
8 #include "esphome/core/log.h"
9 
10 #include <Updater.h>
11 
12 namespace esphome {
13 namespace ota {
14 
15 static const char *const TAG = "ota.arduino_esp8266";
16 
17 std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoESP8266OTABackend>(); }
18 
20  bool ret = Update.begin(image_size, U_FLASH);
21  if (ret) {
23  return OTA_RESPONSE_OK;
24  }
25 
26  uint8_t error = Update.getError();
27  if (error == UPDATE_ERROR_BOOTSTRAP)
29  if (error == UPDATE_ERROR_NEW_FLASH_CONFIG)
31  if (error == UPDATE_ERROR_FLASH_CONFIG)
33  if (error == UPDATE_ERROR_SPACE)
35 
36  ESP_LOGE(TAG, "Begin error: %d", error);
37 
39 }
40 
41 void ArduinoESP8266OTABackend::set_update_md5(const char *md5) { Update.setMD5(md5); }
42 
44  size_t written = Update.write(data, len);
45  if (written == len) {
46  return OTA_RESPONSE_OK;
47  }
48 
49  uint8_t error = Update.getError();
50  ESP_LOGE(TAG, "Write error: %d", error);
51 
53 }
54 
56  if (Update.end()) {
57  return OTA_RESPONSE_OK;
58  }
59 
60  uint8_t error = Update.getError();
61  ESP_LOGE(TAG, "End error: %d", error);
62 
64 }
65 
67  Update.end();
69 }
70 
71 } // namespace ota
72 } // namespace esphome
73 
74 #endif
75 #endif
OTAResponseTypes begin(size_t image_size) override
std::unique_ptr< ota::OTABackend > make_ota_backend()
std::string size_t len
Definition: helpers.h:293
OTAResponseTypes write(uint8_t *data, size_t len) override
void preferences_prevent_write(bool prevent)
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7