mirror of
https://github.com/esphome/esphome.git
synced 2025-08-06 18:37:47 +00:00
fix ota
This commit is contained in:
parent
246527e618
commit
2f8f6967bf
@ -4,6 +4,15 @@
|
|||||||
#include "esphome/core/defines.h"
|
#include "esphome/core/defines.h"
|
||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
|
|
||||||
|
#include "ota_component.h"
|
||||||
|
|
||||||
|
// Extended OTAState enum to include additional states needed by backends
|
||||||
|
// but not exposed in the main component interface
|
||||||
|
#ifndef OTA_ABORT
|
||||||
|
#define OTA_ABORT 3
|
||||||
|
#define OTA_ERROR 4
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_OTA_STATE_CALLBACK
|
#ifdef USE_OTA_STATE_CALLBACK
|
||||||
#include "esphome/core/automation.h"
|
#include "esphome/core/automation.h"
|
||||||
#endif
|
#endif
|
||||||
@ -11,43 +20,6 @@
|
|||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace ota {
|
namespace ota {
|
||||||
|
|
||||||
enum OTAResponseTypes {
|
|
||||||
OTA_RESPONSE_OK = 0x00,
|
|
||||||
OTA_RESPONSE_REQUEST_AUTH = 0x01,
|
|
||||||
|
|
||||||
OTA_RESPONSE_HEADER_OK = 0x40,
|
|
||||||
OTA_RESPONSE_AUTH_OK = 0x41,
|
|
||||||
OTA_RESPONSE_UPDATE_PREPARE_OK = 0x42,
|
|
||||||
OTA_RESPONSE_BIN_MD5_OK = 0x43,
|
|
||||||
OTA_RESPONSE_RECEIVE_OK = 0x44,
|
|
||||||
OTA_RESPONSE_UPDATE_END_OK = 0x45,
|
|
||||||
OTA_RESPONSE_SUPPORTS_COMPRESSION = 0x46,
|
|
||||||
OTA_RESPONSE_CHUNK_OK = 0x47,
|
|
||||||
|
|
||||||
OTA_RESPONSE_ERROR_MAGIC = 0x80,
|
|
||||||
OTA_RESPONSE_ERROR_UPDATE_PREPARE = 0x81,
|
|
||||||
OTA_RESPONSE_ERROR_AUTH_INVALID = 0x82,
|
|
||||||
OTA_RESPONSE_ERROR_WRITING_FLASH = 0x83,
|
|
||||||
OTA_RESPONSE_ERROR_UPDATE_END = 0x84,
|
|
||||||
OTA_RESPONSE_ERROR_INVALID_BOOTSTRAPPING = 0x85,
|
|
||||||
OTA_RESPONSE_ERROR_WRONG_CURRENT_FLASH_CONFIG = 0x86,
|
|
||||||
OTA_RESPONSE_ERROR_WRONG_NEW_FLASH_CONFIG = 0x87,
|
|
||||||
OTA_RESPONSE_ERROR_ESP8266_NOT_ENOUGH_SPACE = 0x88,
|
|
||||||
OTA_RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE = 0x89,
|
|
||||||
OTA_RESPONSE_ERROR_NO_UPDATE_PARTITION = 0x8A,
|
|
||||||
OTA_RESPONSE_ERROR_MD5_MISMATCH = 0x8B,
|
|
||||||
OTA_RESPONSE_ERROR_RP2040_NOT_ENOUGH_SPACE = 0x8C,
|
|
||||||
OTA_RESPONSE_ERROR_UNKNOWN = 0xFF,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum OTAState {
|
|
||||||
OTA_COMPLETED = 0,
|
|
||||||
OTA_STARTED,
|
|
||||||
OTA_IN_PROGRESS,
|
|
||||||
OTA_ABORT,
|
|
||||||
OTA_ERROR,
|
|
||||||
};
|
|
||||||
|
|
||||||
class OTABackend {
|
class OTABackend {
|
||||||
public:
|
public:
|
||||||
virtual ~OTABackend() = default;
|
virtual ~OTABackend() = default;
|
||||||
@ -59,18 +31,6 @@ class OTABackend {
|
|||||||
virtual bool supports_compression() = 0;
|
virtual bool supports_compression() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OTAComponent : public Component {
|
|
||||||
#ifdef USE_OTA_STATE_CALLBACK
|
|
||||||
public:
|
|
||||||
void add_on_state_callback(std::function<void(ota::OTAState, float, uint8_t)> &&callback) {
|
|
||||||
this->state_callback_.add(std::move(callback));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
CallbackManager<void(ota::OTAState, float, uint8_t)> state_callback_{};
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef USE_OTA_STATE_CALLBACK
|
#ifdef USE_OTA_STATE_CALLBACK
|
||||||
class OTAGlobalCallback {
|
class OTAGlobalCallback {
|
||||||
public:
|
public:
|
||||||
@ -90,7 +50,8 @@ class OTAGlobalCallback {
|
|||||||
OTAGlobalCallback *get_global_ota_callback();
|
OTAGlobalCallback *get_global_ota_callback();
|
||||||
void register_ota_platform(OTAComponent *ota_caller);
|
void register_ota_platform(OTAComponent *ota_caller);
|
||||||
#endif
|
#endif
|
||||||
std::unique_ptr<ota::OTABackend> make_ota_backend();
|
// This function is defined in ota_component.cpp
|
||||||
|
std::unique_ptr<OTABackend> make_ota_backend();
|
||||||
|
|
||||||
} // namespace ota
|
} // namespace ota
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
@ -12,7 +12,7 @@ namespace ota {
|
|||||||
|
|
||||||
static const char *const TAG = "ota.arduino_esp32";
|
static const char *const TAG = "ota.arduino_esp32";
|
||||||
|
|
||||||
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoESP32OTABackend>(); }
|
// Function is now defined in ota_component.cpp
|
||||||
|
|
||||||
OTAResponseTypes ArduinoESP32OTABackend::begin(size_t image_size) {
|
OTAResponseTypes ArduinoESP32OTABackend::begin(size_t image_size) {
|
||||||
bool ret = Update.begin(image_size, U_FLASH);
|
bool ret = Update.begin(image_size, U_FLASH);
|
||||||
|
@ -14,7 +14,7 @@ namespace ota {
|
|||||||
|
|
||||||
static const char *const TAG = "ota.arduino_esp8266";
|
static const char *const TAG = "ota.arduino_esp8266";
|
||||||
|
|
||||||
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoESP8266OTABackend>(); }
|
// Function is now defined in ota_component.cpp
|
||||||
|
|
||||||
OTAResponseTypes ArduinoESP8266OTABackend::begin(size_t image_size) {
|
OTAResponseTypes ArduinoESP8266OTABackend::begin(size_t image_size) {
|
||||||
bool ret = Update.begin(image_size, U_FLASH);
|
bool ret = Update.begin(image_size, U_FLASH);
|
||||||
|
@ -12,7 +12,7 @@ namespace ota {
|
|||||||
|
|
||||||
static const char *const TAG = "ota.arduino_libretiny";
|
static const char *const TAG = "ota.arduino_libretiny";
|
||||||
|
|
||||||
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoLibreTinyOTABackend>(); }
|
// Function is now defined in ota_component.cpp
|
||||||
|
|
||||||
OTAResponseTypes ArduinoLibreTinyOTABackend::begin(size_t image_size) {
|
OTAResponseTypes ArduinoLibreTinyOTABackend::begin(size_t image_size) {
|
||||||
bool ret = Update.begin(image_size, U_FLASH);
|
bool ret = Update.begin(image_size, U_FLASH);
|
||||||
|
@ -14,7 +14,7 @@ namespace ota {
|
|||||||
|
|
||||||
static const char *const TAG = "ota.arduino_rp2040";
|
static const char *const TAG = "ota.arduino_rp2040";
|
||||||
|
|
||||||
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoRP2040OTABackend>(); }
|
// Function is now defined in ota_component.cpp
|
||||||
|
|
||||||
OTAResponseTypes ArduinoRP2040OTABackend::begin(size_t image_size) {
|
OTAResponseTypes ArduinoRP2040OTABackend::begin(size_t image_size) {
|
||||||
bool ret = Update.begin(image_size, U_FLASH);
|
bool ret = Update.begin(image_size, U_FLASH);
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace ota {
|
namespace ota {
|
||||||
|
|
||||||
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::IDFOTABackend>(); }
|
// Function is now defined in ota_component.cpp
|
||||||
|
|
||||||
OTAResponseTypes IDFOTABackend::begin(size_t image_size) {
|
OTAResponseTypes IDFOTABackend::begin(size_t image_size) {
|
||||||
this->partition_ = esp_ota_get_next_update_partition(nullptr);
|
this->partition_ = esp_ota_get_next_update_partition(nullptr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user