Skip to content

Commit 6bc2dd4

Browse files
committed
OTA: add setFetchmode
1 parent c05f1ed commit 6bc2dd4

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/ArduinoIoTCloudTCP.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
168168

169169
#if OTA_ENABLED && !defined(OFFLOADED_DOWNLOAD)
170170
_ota.setClient(&_otaClient);
171+
if (_connection->getInterface() == NetworkAdapter::ETHERNET) {
172+
_ota.setFetchMode(OTADefaultCloudProcessInterface::OtaFetchChunk);
173+
}
171174
#endif // OTA_ENABLED && !defined(OFFLOADED_DOWNLOAD)
172175

173176
#if OTA_ENABLED && defined(OTA_BASIC_AUTH)

src/ota/interface/OTAInterfaceDefault.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ OTADefaultCloudProcessInterface::OTADefaultCloudProcessInterface(MessageStream *
2020
, client(client)
2121
, http_client(nullptr)
2222
, username(nullptr), password(nullptr)
23+
, fetchMode(OtaFetchTime)
2324
, context(nullptr) {
2425
}
2526

@@ -85,12 +86,13 @@ OTACloudProcessInterface::State OTADefaultCloudProcessInterface::startOTA() {
8586
}
8687

8788
context->lastReportTime = millis();
89+
DEBUG_VERBOSE("OTA file length: %d", context->contentLength);
8890

8991
return Fetch;
9092
}
9193

9294
OTACloudProcessInterface::State OTADefaultCloudProcessInterface::fetch() {
93-
if(downloadTime > 0) {
95+
if(fetchMode == OtaFetchTime) {
9496
return fetchTime();
9597
} else {
9698
return fetchChunk();

src/ota/interface/OTAInterfaceDefault.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ class OTADefaultCloudProcessInterface: public OTACloudProcessInterface {
3535
this->password = password;
3636
}
3737

38+
enum OTAFetchMode: uint8_t {
39+
OtaFetchTime,
40+
OtaFetchChunk
41+
};
42+
43+
inline virtual void setFetchMode(OTAFetchMode mode) { this->fetchMode = mode; }
44+
3845
protected:
3946
State startOTA();
4047
State fetch();
@@ -50,6 +57,7 @@ class OTADefaultCloudProcessInterface: public OTACloudProcessInterface {
5057
HttpClient* http_client;
5158

5259
const char *username, *password;
60+
OTAFetchMode fetchMode;
5361

5462
// The amount of time that each iteration of Fetch has to take at least
5563
// This mitigate the issues arising from tasks run in main loop that are using all the computing time

0 commit comments

Comments
 (0)