From 941266129a2a65ddfebca021fbd416064ea86b1c Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 8 Nov 2024 13:20:44 +0100 Subject: [PATCH 1/2] fix ota download byte count --- src/ota/interface/OTAInterfaceDefault.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/ota/interface/OTAInterfaceDefault.cpp b/src/ota/interface/OTAInterfaceDefault.cpp index 4f68d774c..82bfd9e82 100644 --- a/src/ota/interface/OTAInterfaceDefault.cpp +++ b/src/ota/interface/OTAInterfaceDefault.cpp @@ -159,10 +159,10 @@ void OTADefaultCloudProcessInterface::parseOta(uint8_t* buffer, size_t buf_len) for(uint8_t* cursor=(uint8_t*)buffer; cursordownloadState) { case OtaDownloadHeader: { - uint32_t copied = buf_len < sizeof(context->header.buf) ? buf_len : sizeof(context->header.buf); - memcpy(context->header.buf+context->headerCopiedBytes, buffer, copied); - cursor += copied; - context->headerCopiedBytes += copied; + const uint32_t headerLeft = context->headerCopiedBytes + buf_len <= sizeof(context->header.buf) ? buf_len : sizeof(context->header.buf) - context->headerCopiedBytes; + memcpy(context->header.buf+context->headerCopiedBytes, buffer, headerLeft); + cursor += headerLeft; + context->headerCopiedBytes += headerLeft; // when finished go to next state if(sizeof(context->header.buf) == context->headerCopiedBytes) { @@ -178,22 +178,24 @@ void OTADefaultCloudProcessInterface::parseOta(uint8_t* buffer, size_t buf_len) context->downloadState = OtaDownloadMagicNumberMismatch; return; } + context->downloadedSize += sizeof(context->header.buf); } break; } case OtaDownloadFile: { - uint32_t contentLength = http_client->contentLength(); - context->decoder.decompress(cursor, buf_len - (cursor-buffer)); // TODO verify return value + const uint32_t contentLength = http_client->contentLength(); + const uint32_t dataLeft = buf_len - (cursor-buffer); + context->decoder.decompress(cursor, dataLeft); // TODO verify return value context->calculatedCrc32 = crc_update( context->calculatedCrc32, cursor, - buf_len - (cursor-buffer) + dataLeft ); - cursor += buf_len - (cursor-buffer); - context->downloadedSize += (cursor-buffer); + cursor += dataLeft; + context->downloadedSize += dataLeft; if((millis() - context->lastReportTime) > 10000) { // Report the download progress each X millisecond DEBUG_VERBOSE("OTA Download Progress %d/%d", context->downloadedSize, contentLength); From d97fe3196d8c646c47ed9d838279e5746d00799c Mon Sep 17 00:00:00 2001 From: pennam Date: Wed, 20 Nov 2024 09:45:55 +0100 Subject: [PATCH 2/2] Release v2.1.2 --- library.properties | 2 +- src/AIoTC_Config.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index ac33baf6d..fd97626cf 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArduinoIoTCloud -version=2.1.1 +version=2.1.2 author=Arduino maintainer=Arduino sentence=This library allows connecting to the Arduino IoT Cloud service. diff --git a/src/AIoTC_Config.h b/src/AIoTC_Config.h index 0649c74ae..b3be38488 100644 --- a/src/AIoTC_Config.h +++ b/src/AIoTC_Config.h @@ -178,6 +178,6 @@ #define AIOT_CONFIG_LASTVALUES_SYNC_MAX_RETRY_CNT (10UL) #endif -#define AIOT_CONFIG_LIB_VERSION "2.1.1" +#define AIOT_CONFIG_LIB_VERSION "2.1.2" #endif /* ARDUINO_AIOTC_CONFIG_H_ */