ESPHome  2022.8.0
ota_backend_arduino_esp8266.cpp
Go to the documentation of this file.
1 #include "esphome/core/defines.h"
2 #ifdef USE_ARDUINO
3 #ifdef USE_ESP8266
4 
6 #include "ota_component.h"
7 #include "ota_backend.h"
9 
10 #include <Updater.h>
11 
12 namespace esphome {
13 namespace ota {
14 
16  bool ret = Update.begin(image_size, U_FLASH);
17  if (ret) {
19  return OTA_RESPONSE_OK;
20  }
21 
22  uint8_t error = Update.getError();
23  if (error == UPDATE_ERROR_BOOTSTRAP)
25  if (error == UPDATE_ERROR_NEW_FLASH_CONFIG)
27  if (error == UPDATE_ERROR_FLASH_CONFIG)
29  if (error == UPDATE_ERROR_SPACE)
32 }
33 
34 void ArduinoESP8266OTABackend::set_update_md5(const char *md5) { Update.setMD5(md5); }
35 
37  size_t written = Update.write(data, len);
38  if (written != len) {
40  }
41  return OTA_RESPONSE_OK;
42 }
43 
45  if (!Update.end())
47  return OTA_RESPONSE_OK;
48 }
49 
51  Update.end();
53 }
54 
55 } // namespace ota
56 } // namespace esphome
57 
58 #endif
59 #endif
OTAResponseTypes begin(size_t image_size) override
std::string size_t len
Definition: helpers.h:278
OTAResponseTypes write(uint8_t *data, size_t len) override
void preferences_prevent_write(bool prevent)
Definition: a4988.cpp:4