ESPHome 2025.5.0
Loading...
Searching...
No Matches
ota_http_request.h
Go to the documentation of this file.
1#pragma once
2
7
8#include <memory>
9#include <string>
10#include <utility>
11
12#include "../http_request.h"
13
14namespace esphome {
15namespace http_request {
16
17static const uint8_t MD5_SIZE = 32;
18
24
25class OtaHttpRequestComponent : public ota::OTAComponent, public Parented<HttpRequestComponent> {
26 public:
27 void setup() override;
28 void dump_config() override;
29 float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
30
31 void set_md5_url(const std::string &md5_url);
32 void set_md5(const std::string &md5) { this->md5_expected_ = md5; }
33 void set_password(const std::string &password) { this->password_ = password; }
34 void set_url(const std::string &url);
35 void set_username(const std::string &username) { this->username_ = username; }
36
37 std::string md5_computed() { return this->md5_computed_; }
38 std::string md5_expected() { return this->md5_expected_; }
39
40 void flash();
41
42 protected:
43 void cleanup_(std::unique_ptr<ota::OTABackend> backend, const std::shared_ptr<HttpContainer> &container);
44 uint8_t do_ota_();
45 std::string get_url_with_auth_(const std::string &url);
46 bool http_get_md5_();
47 bool validate_url_(const std::string &url);
48
49 std::string md5_computed_{};
50 std::string md5_expected_{};
51 std::string md5_url_{};
52 std::string password_{};
53 std::string username_{};
54 std::string url_{};
55 int status_ = -1;
56 bool update_started_ = false;
57 static const uint16_t HTTP_RECV_BUFFER = 256; // the firmware GET chunk size
58};
59
60} // namespace http_request
61} // namespace esphome
Helper class to easily give an object a parent of type T.
Definition helpers.h:538
void cleanup_(std::unique_ptr< ota::OTABackend > backend, const std::shared_ptr< HttpContainer > &container)
void set_password(const std::string &password)
void set_username(const std::string &username)
std::string get_url_with_auth_(const std::string &url)
void set_md5_url(const std::string &md5_url)
const float AFTER_WIFI
For components that should be initialized after WiFi is connected.
Definition component.cpp:26
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7