Skip to content

Commit

Permalink
OTA: add setFetchmode
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Dec 11, 2024
1 parent ce3e5af commit 7e89f55
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/ota/interface/OTAInterfaceDefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ OTADefaultCloudProcessInterface::OTADefaultCloudProcessInterface(MessageStream *
, client(client)
, http_client(nullptr)
, username(nullptr), password(nullptr)
, fetchMode(OtaFetchTime)
, context(nullptr) {
}

Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/ota/interface/OTAInterfaceDefault.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down

0 comments on commit 7e89f55

Please sign in to comment.