From 7e89f55764d55d2674aeb4a95cb1be43e7bcf75d Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 10 Dec 2024 12:21:17 +0100 Subject: [PATCH] OTA: add setFetchmode --- src/ArduinoIoTCloudTCP.cpp | 3 +++ src/ota/interface/OTAInterfaceDefault.cpp | 4 +++- src/ota/interface/OTAInterfaceDefault.h | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index 121e2632..6a49e867 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -168,6 +168,9 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress, #if OTA_ENABLED && !defined(OFFLOADED_DOWNLOAD) _ota.setClient(&_otaClient); + if (_connection->getInterface() == NetworkAdapter::ETHERNET) { + _ota.setFetchMode(OTADefaultCloudProcessInterface::OtaFetchChunk); + } #endif // OTA_ENABLED && !defined(OFFLOADED_DOWNLOAD) #if OTA_ENABLED && defined(OTA_BASIC_AUTH) diff --git a/src/ota/interface/OTAInterfaceDefault.cpp b/src/ota/interface/OTAInterfaceDefault.cpp index 0d7d7ff4..e18461c2 100644 --- a/src/ota/interface/OTAInterfaceDefault.cpp +++ b/src/ota/interface/OTAInterfaceDefault.cpp @@ -20,6 +20,7 @@ OTADefaultCloudProcessInterface::OTADefaultCloudProcessInterface(MessageStream * , client(client) , http_client(nullptr) , username(nullptr), password(nullptr) +, fetchMode(OtaFetchTime) , context(nullptr) { } @@ -85,12 +86,13 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() { } context->lastReportTime = millis(); + DEBUG_VERBOSE("OTA file length: %d", context->contentLength); return Fetch; } OTACloudProcessInterface::State OTADefaultCloudProcessInterface::fetch() { - if(downloadTime > 0) { + if(fetchMode == OtaFetchTime) { return fetchTime(); } else { return fetchChunk(); diff --git a/src/ota/interface/OTAInterfaceDefault.h b/src/ota/interface/OTAInterfaceDefault.h index ae4f808f..aa441148 100644 --- a/src/ota/interface/OTAInterfaceDefault.h +++ b/src/ota/interface/OTAInterfaceDefault.h @@ -35,6 +35,13 @@ class OTADefaultCloudProcessInterface: public OTACloudProcessInterface { this->password = password; } + enum OTAFetchMode: uint8_t { + OtaFetchTime, + OtaFetchChunk + }; + + inline virtual void setFetchMode(OTAFetchMode mode) { this->fetchMode = mode; } + protected: State startOTA(); State fetch(); @@ -50,6 +57,7 @@ class OTADefaultCloudProcessInterface: public OTACloudProcessInterface { HttpClient* http_client; const char *username, *password; + OTAFetchMode fetchMode; // The amount of time that each iteration of Fetch has to take at least // This mitigate the issues arising from tasks run in main loop that are using all the computing time