Skip to content

Commit 0524d0a

Browse files
committed
net: lib: nrf_cloud_fota_poll: Improvements and fixes
This patch includes several improvements and fixes to the nRF Cloud CoAP FOTA polling library. The changes are as follows: - Added a new API to apply the FOTA update after download, enabling asynchronous use and allowing the application to control when to shut down the modem pre applying a new modem image. This improves separation of concerns and modularity. For synchronous use, shutdown and FOTA application are handled internally by the library in the same function call. - The library now polls every 10 percent for the status of the job to check if it has been canceled by the cloud during download. Previously, the library would simply download the firmware and apply it without verifying whether the job had been canceled by the cloud. - Minor refactoring for improved readability and maintainability of the code. For an example of using the asynchronous API, see: https://github.com/nrfconnect/Asset-Tracker-Template Signed-off-by: Simen S. Røstad <simen.rostad@nordicsemi.no>
1 parent 4f46b35 commit 0524d0a

File tree

6 files changed

+179
-54
lines changed

6 files changed

+179
-54
lines changed

include/net/nrf_cloud.h

+6
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,12 @@ enum nrf_cloud_fota_status {
294294
NRF_CLOUD_FOTA_CANCELED = 5,
295295
NRF_CLOUD_FOTA_REJECTED = 6,
296296
NRF_CLOUD_FOTA_DOWNLOADING = 7,
297+
298+
/* Validation for Full modem FOTA needed, disconnect from LTE network and call
299+
* nrf_cloud_fota_poll_update_apply(). This event is not reported to nRF Cloud and is only
300+
* used internally to signal the application to apply the full modem FOTA update.
301+
*/
302+
NRF_CLOUD_FOTA_FMFU_VALIDATION_NEEDED = 8,
297303
};
298304

299305
/** @brief FOTA update type. */

include/net/nrf_cloud_fota_poll.h

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct nrf_cloud_fota_poll_ctx {
5151
/* Internal variables */
5252
struct nrf_cloud_rest_context *rest_ctx;
5353
struct k_work_delayable timeout_work;
54+
struct k_work_delayable cancel_work;
5455
bool is_nonblocking;
5556
bool full_modem_fota_supported;
5657
const char *device_id;
@@ -136,6 +137,16 @@ int nrf_cloud_fota_poll_process_pending(struct nrf_cloud_fota_poll_ctx *ctx);
136137
*/
137138
int nrf_cloud_fota_poll_process(struct nrf_cloud_fota_poll_ctx *ctx);
138139

140+
/**
141+
* @brief Apply downloaded image. For full modem FOTA this must be called after the network has
142+
* been disconnected. Only applicable in non-blocking mode.
143+
*
144+
* @param[in] ctx Pointer to context used for FOTA polling operations.
145+
*
146+
* @return 0 on success, negative value on failure.
147+
*/
148+
int nrf_cloud_fota_poll_update_apply(struct nrf_cloud_fota_poll_ctx *ctx);
149+
139150
/** @} */
140151

141152
#ifdef __cplusplus

samples/cellular/nrf_cloud_multi_service/prj.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ CONFIG_FCB=y
117117

118118
# Download Client - used by FOTA and PGPS
119119
CONFIG_DOWNLOADER=y
120-
CONFIG_DOWNLOADER_STACK_SIZE=4096
120+
CONFIG_DOWNLOADER_STACK_SIZE=4352
121121
CONFIG_DOWNLOADER_MAX_HOSTNAME_SIZE=128
122122

123123
# Flash - Used by FOTA and PGPS

subsys/net/lib/downloader/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ comment "Thread and stack buffers"
1313

1414
config DOWNLOADER_STACK_SIZE
1515
int "Thread stack size"
16-
range 768 4096
16+
range 768 8192
1717
default 1280
1818

1919
config DOWNLOADER_MAX_HOSTNAME_SIZE

subsys/net/lib/nrf_cloud/Kconfig.nrf_cloud_fota

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ config NRF_CLOUD_FOTA_POLL
5050
bool "FOTA job polling helpers (REST/CoAP)"
5151
depends on !NRF_CLOUD_FOTA
5252
depends on FOTA_DOWNLOAD
53+
select FOTA_DOWNLOAD_PROGRESS_EVT
5354
help
5455
When enabled, nRF Cloud FOTA job polling helpers will be built. These
5556
functions make it easy to request, download, and handle modem, boot,

0 commit comments

Comments
 (0)