mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-27 08:18:28 +02:00
7b45498de6
* Implement http_request component for esp-idf * Fix ifdefs * Lint * clang * Set else to fail with error message * Use unique_ptr * Fix * Tidy up casting, explicit HttpResponse lifetime (#3265) Co-authored-by: Daniel Cousens <dcousens@users.noreply.github.com> * Remove unique_ptr wrapper * Fix * Use reference * Add duration code into new split files * Add config for tx/rx buffer on idf * Fix * Try reserve response data with rx buffer size * Update http_request.h * Move client cleanup to be earlier * Move capture_response to bool on struct and remove global * Fix returns * Change quotes to brackets * Rework http request * Remove http request from old test yamls * Update component tests * Validate md5 length when hardcoded string * Linting * Add duration_ms to container * More lint * const * Remove default arguments and add helper functions for get and post * Add virtual destructor to HttpContainer * Undo const HEADER_KEYS * 🤦 * Update esphome/components/http_request/ota/ota_http_request.cpp Co-authored-by: Keith Burzinski <kbx81x@gmail.com> * Update esphome/components/http_request/ota/ota_http_request.cpp Co-authored-by: Keith Burzinski <kbx81x@gmail.com> * lint * Move header keys inline * Add missing WatchdogManagers * CAPS * Fix "follow redirects" string in config dump * IDF 5+ fix --------- Co-authored-by: Daniel Cousens <413395+dcousens@users.noreply.github.com> Co-authored-by: Daniel Cousens <dcousens@users.noreply.github.com> Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
63 lines
1.8 KiB
C++
63 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include "esphome/components/ota/ota_backend.h"
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/core/defines.h"
|
|
#include "esphome/core/helpers.h"
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
#include "../http_request.h"
|
|
|
|
namespace esphome {
|
|
namespace http_request {
|
|
|
|
static const char *const TAG = "http_request.ota";
|
|
static const uint8_t MD5_SIZE = 32;
|
|
|
|
enum OtaHttpRequestError : uint8_t {
|
|
OTA_MD5_INVALID = 0x10,
|
|
OTA_BAD_URL = 0x11,
|
|
OTA_CONNECTION_ERROR = 0x12,
|
|
};
|
|
|
|
class OtaHttpRequestComponent : public ota::OTAComponent, public Parented<HttpRequestComponent> {
|
|
public:
|
|
void setup() override;
|
|
void dump_config() override;
|
|
float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
|
|
|
|
void set_md5_url(const std::string &md5_url);
|
|
void set_md5(const std::string &md5) { this->md5_expected_ = md5; }
|
|
void set_password(const std::string &password) { this->password_ = password; }
|
|
void set_url(const std::string &url);
|
|
void set_username(const std::string &username) { this->username_ = username; }
|
|
|
|
std::string md5_computed() { return this->md5_computed_; }
|
|
std::string md5_expected() { return this->md5_expected_; }
|
|
|
|
void flash();
|
|
|
|
protected:
|
|
void cleanup_(std::unique_ptr<ota::OTABackend> backend, const std::shared_ptr<HttpContainer> &container);
|
|
uint8_t do_ota_();
|
|
std::string get_url_with_auth_(const std::string &url);
|
|
bool http_get_md5_();
|
|
bool validate_url_(const std::string &url);
|
|
|
|
std::string md5_computed_{};
|
|
std::string md5_expected_{};
|
|
std::string md5_url_{};
|
|
std::string password_{};
|
|
std::string username_{};
|
|
std::string url_{};
|
|
int status_ = -1;
|
|
bool update_started_ = false;
|
|
static const uint16_t HTTP_RECV_BUFFER = 256; // the firmware GET chunk size
|
|
};
|
|
|
|
} // namespace http_request
|
|
} // namespace esphome
|