mirror of
https://github.com/esphome/esphome.git
synced 2025-09-07 22:02:22 +01:00
adjust
This commit is contained in:
@@ -20,6 +20,8 @@ namespace esphome {
|
|||||||
|
|
||||||
static const char *const TAG = "esphome.ota";
|
static const char *const TAG = "esphome.ota";
|
||||||
static constexpr u_int16_t OTA_BLOCK_SIZE = 8192;
|
static constexpr u_int16_t OTA_BLOCK_SIZE = 8192;
|
||||||
|
static constexpr uint32_t OTA_SOCKET_TIMEOUT_HANDSHAKE = 10000; // milliseconds for initial handshake
|
||||||
|
static constexpr uint32_t OTA_SOCKET_TIMEOUT_DATA = 90000; // milliseconds for data transfer
|
||||||
|
|
||||||
void ESPHomeOTAComponent::setup() {
|
void ESPHomeOTAComponent::setup() {
|
||||||
#ifdef USE_OTA_STATE_CALLBACK
|
#ifdef USE_OTA_STATE_CALLBACK
|
||||||
@@ -407,12 +409,12 @@ error:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ESPHomeOTAComponent::readall_(uint8_t *buf, size_t len, uint32_t timeout) {
|
bool ESPHomeOTAComponent::readall_(uint8_t *buf, size_t len) {
|
||||||
uint32_t start = millis();
|
uint32_t start = millis();
|
||||||
uint32_t at = 0;
|
uint32_t at = 0;
|
||||||
while (len - at > 0) {
|
while (len - at > 0) {
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
if (now - start > timeout) {
|
if (now - start > OTA_SOCKET_TIMEOUT_DATA) {
|
||||||
ESP_LOGW(TAG, "Timeout reading %d bytes", len);
|
ESP_LOGW(TAG, "Timeout reading %d bytes", len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -438,12 +440,12 @@ bool ESPHomeOTAComponent::readall_(uint8_t *buf, size_t len, uint32_t timeout) {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool ESPHomeOTAComponent::writeall_(const uint8_t *buf, size_t len, uint32_t timeout) {
|
bool ESPHomeOTAComponent::writeall_(const uint8_t *buf, size_t len) {
|
||||||
uint32_t start = millis();
|
uint32_t start = millis();
|
||||||
uint32_t at = 0;
|
uint32_t at = 0;
|
||||||
while (len - at > 0) {
|
while (len - at > 0) {
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
if (now - start > timeout) {
|
if (now - start > OTA_SOCKET_TIMEOUT_DATA) {
|
||||||
ESP_LOGW(TAG, "Timeout writing %d bytes", len);
|
ESP_LOGW(TAG, "Timeout writing %d bytes", len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -9,9 +9,6 @@
|
|||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
|
|
||||||
static constexpr uint32_t OTA_SOCKET_TIMEOUT_HANDSHAKE = 10000; // milliseconds for initial handshake
|
|
||||||
static constexpr uint32_t OTA_SOCKET_TIMEOUT_DATA = 90000; // milliseconds for data transfer
|
|
||||||
|
|
||||||
/// ESPHomeOTAComponent provides a simple way to integrate Over-the-Air updates into your app using ArduinoOTA.
|
/// ESPHomeOTAComponent provides a simple way to integrate Over-the-Air updates into your app using ArduinoOTA.
|
||||||
class ESPHomeOTAComponent : public ota::OTAComponent {
|
class ESPHomeOTAComponent : public ota::OTAComponent {
|
||||||
public:
|
public:
|
||||||
@@ -32,8 +29,8 @@ class ESPHomeOTAComponent : public ota::OTAComponent {
|
|||||||
protected:
|
protected:
|
||||||
void handle_handshake_();
|
void handle_handshake_();
|
||||||
void handle_data_();
|
void handle_data_();
|
||||||
bool readall_(uint8_t *buf, size_t len, uint32_t timeout = OTA_SOCKET_TIMEOUT_DATA);
|
bool readall_(uint8_t *buf, size_t len);
|
||||||
bool writeall_(const uint8_t *buf, size_t len, uint32_t timeout = OTA_SOCKET_TIMEOUT_DATA);
|
bool writeall_(const uint8_t *buf, size_t len);
|
||||||
void log_socket_error_(const char *msg);
|
void log_socket_error_(const char *msg);
|
||||||
void log_start_(const char *phase);
|
void log_start_(const char *phase);
|
||||||
void cleanup_connection_();
|
void cleanup_connection_();
|
||||||
@@ -43,10 +40,10 @@ class ESPHomeOTAComponent : public ota::OTAComponent {
|
|||||||
#endif // USE_OTA_PASSWORD
|
#endif // USE_OTA_PASSWORD
|
||||||
|
|
||||||
uint16_t port_;
|
uint16_t port_;
|
||||||
|
uint32_t client_connect_time_{0};
|
||||||
|
|
||||||
std::unique_ptr<socket::Socket> server_;
|
std::unique_ptr<socket::Socket> server_;
|
||||||
std::unique_ptr<socket::Socket> client_;
|
std::unique_ptr<socket::Socket> client_;
|
||||||
uint32_t client_connect_time_{0};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
Reference in New Issue
Block a user