Skip to content

Commit 9947077

Browse files
committed
samples: cellular: Add nrf_cloud_mqtt_fota
This demonstrates how to use FOTA over MQTT with nRF Cloud JIRA: IRIS-10200 Signed-off-by: Pascal Hernandez <pascal.hernandez@nordicsemi.no>
1 parent cc348c5 commit 9947077

21 files changed

+1219
-0
lines changed

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ Cellular samples
466466
* The :ref:`nrf_cloud_coap_fota_sample` sample to demonstrate how to use the `nRF Cloud CoAP API`_ for FOTA updates.
467467
* The :ref:`nrf_cloud_coap_device_message` sample to demonstrate how to use the `nRF Cloud CoAP API`_ for device messages.
468468
* The :ref:`nrf_cloud_mqtt_device_message` sample to demonstrate how to use the `nRF Cloud MQTT API`_ for device messages.
469+
* The :ref:`nrf_cloud_mqtt_fota` sample to demonstrate how to use the `nRF Cloud MQTT API`_ for FOTA updates.
469470

470471
* Removed the SLM Shell sample.
471472
Use the `Serial Modem Host Shell`_ sample instead.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
project(nrf_cloud_mqtt_fota_sample)
11+
12+
# NORDIC SDK APP START
13+
target_sources(app PRIVATE src/main.c)
14+
15+
if(CONFIG_NRF_CLOUD_FOTA_SMP AND CONFIG_BOARD_NRF9160DK_NRF9160_NS)
16+
target_sources(app PRIVATE src/smp_reset.c)
17+
endif()
18+
# NORDIC SDK APP END
19+
20+
zephyr_include_directories(src)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
menu "nRF Cloud MQTT FOTA Sample"
8+
9+
config CLOUD_CONNECTION_RETRY_TIMEOUT_SECONDS
10+
int "Cloud connection retry timeout (seconds)"
11+
default 30
12+
help
13+
If connecting to nRF Cloud takes longer than this timeout, it will be
14+
reattempted.
15+
16+
config CLOUD_READY_TIMEOUT_SECONDS
17+
int "Cloud readiness timeout (seconds)"
18+
default 600
19+
help
20+
If the connection to nRF Cloud does not become ready within this
21+
timeout, the sample will reset its connection and try again.
22+
23+
module = NRF_CLOUD_MQTT_FOTA_SAMPLE
24+
module-str = nRF Cloud MQTT FOTA Sample
25+
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
26+
27+
endmenu
28+
29+
menu "Zephyr Kernel"
30+
source "Kconfig.zephyr"
31+
endmenu
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
.. _nrf_cloud_mqtt_fota:
2+
3+
Cellular: nRF Cloud MQTT FOTA
4+
#############################
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
The nRF Cloud MQTT FOTA sample demonstrates how to use the `nRF Cloud MQTT API`_ to perform Firmware Over-The-Air (FOTA) updates over MQTT on your device.
11+
This covers modem, application, and full modem FOTA updates (FMFU).
12+
Also, with the nRF9160 DK, it supports SMP FOTA updates to the firmware on the nRF52840 SoC present on the DK board (not a separate device).
13+
14+
When using MQTT, the `FOTA update <nRF Cloud Getting Started FOTA Documentation_>`_ support is almost entirely implemented by enabling the :kconfig:option:`CONFIG_NRF_CLOUD_FOTA` option, which is implicitly enabled by :kconfig:option:`CONFIG_NRF_CLOUD_MQTT`.
15+
16+
However, even with the :kconfig:option:`CONFIG_NRF_CLOUD_FOTA` Kconfig option enabled, applications must still reboot themselves manually after FOTA download completion, and must still update their `Device Shadow <nRF Cloud Device Shadows_>`_ to reflect FOTA support.
17+
18+
Requirements
19+
************
20+
21+
The sample supports the following development kits:
22+
23+
.. table-from-sample-yaml::
24+
25+
.. include:: /includes/tfm.txt
26+
27+
The sample requires an `nRF Cloud`_ account.
28+
29+
Your device must be onboarded to nRF Cloud.
30+
If it is not, follow the instructions in `Device onboarding <nrf_cloud_mqtt_fota_sample_onboarding_>`_.
31+
32+
.. note::
33+
This sample requires modem firmware v1.3.x or later for an nRF9160 SiP and v2.0.0 or later for nRF9161 and nRF9151 SiPs.
34+
35+
.. include:: /includes/external_flash_nrf91.txt
36+
37+
.. note::
38+
Full modem FOTA requires development kit version 0.14.0 or higher if you are using an nRF9160 DK.
39+
40+
Overview
41+
********
42+
43+
You can update your device firmware on the `nRF Cloud`_ portal or directly through the `nRF Cloud MQTT API`_.
44+
See the `nRF Cloud Getting Started FOTA documentation`_ for details.
45+
46+
47+
User interface
48+
**************
49+
50+
Button 1:
51+
Check for a FOTA update right away without waiting for the timeout.
52+
53+
.. _nrf_cloud_mqtt_fota_sample_onboarding:
54+
55+
Setup
56+
=====
57+
58+
You must onboard your device to nRF Cloud for this sample to function.
59+
You only need to do this once for each device.
60+
61+
To onboard your device, install `nRF Cloud Utils`_ and follow the instructions in the README.
62+
63+
Configuration
64+
*************
65+
66+
|config|
67+
68+
Configuration options
69+
=====================
70+
71+
Check and configure the following configuration options for the sample:
72+
73+
.. _CONFIG_CLOUD_CONNECTION_RETRY_TIMEOUT_S:
74+
75+
CONFIG_CLOUD_CONNECTION_RETRY_TIMEOUT_S - Cloud connection retry timeout (seconds)
76+
Sets the cloud connection retry timeout in seconds.
77+
78+
.. _CONFIG_CLOUD_READY_TIMEOUT_S:
79+
80+
CONFIG_CLOUD_READY_TIMEOUT_S - Cloud readiness timeout (seconds)
81+
Sets the cloud readiness timeout in seconds.
82+
If the connection to nRF Cloud does not become ready within this timeout, the sample will reset its connection and try again.
83+
84+
.. include:: /libraries/modem/nrf_modem_lib/nrf_modem_lib_trace.rst
85+
:start-after: modem_lib_sending_traces_UART_start
86+
:end-before: modem_lib_sending_traces_UART_end
87+
88+
Building and running
89+
********************
90+
91+
.. |sample path| replace:: :file:`samples/cellular/nrf_cloud_mqtt_fota`
92+
93+
.. include:: /includes/build_and_run_ns.txt
94+
95+
The configuration files for this sample are located in the :file:`samples/cellular/nrf_cloud_mqtt_fota` folder.
96+
See :ref:`configure_application` on how to configure the parameters.
97+
98+
To create a FOTA test version of this sample, change the ``PATCHLEVEL`` in the :file:`VERSION` file.
99+
100+
To enable full modem FOTA, add the following parameter to your build command:
101+
102+
``-DEXTRA_CONF_FILE=full_modem_fota.conf``
103+
104+
Also, if you are using an nRF9160 DK, specify your development kit version by appending it to the board name.
105+
For example, if you are using version 1.0.1, use the board name ``nrf9160dk@1.0.1/nrf9160/ns`` in your build command.
106+
107+
To enable SMP FOTA (nRF9160 DK only), add the following parameters to your build command:
108+
109+
* ``-DEXTRA_CONF_FILE=smp_fota.conf``
110+
* ``-DEXTRA_DTC_OVERLAY_FILE=nrf9160dk_mcumgr_client_uart2.overlay``
111+
112+
Once you have flashed your nRF9160 DK, change the switch **SW10** to the **nRF52** position to be able to flash the nRF52840 firmware on the DK.
113+
The nRF52840 device on your DK must be running firmware compatible with SMP, such as the :ref:`smp_svr` sample.
114+
Otherwise, the MQTT FOTA sample cannot connect to the nRF52840 and will keep trying to connect.
115+
Build the :ref:`smp_svr` sample for the ``nrf9160dk/nrf52840`` board with the following parameters:
116+
117+
* ``-DEXTRA_CONF_FILE=overlay-serial.conf``
118+
* ``-DEXTRA_DTC_OVERLAY_FILE=nrf9160dk_nrf52840_mcumgr_svr.overlay``
119+
120+
To change :ref:`smp_svr` sample's application version, set the :kconfig:option:`CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION` Kconfig option.
121+
122+
Testing
123+
=======
124+
125+
|test_sample|
126+
127+
#. |connect_kit|
128+
#. |connect_terminal|
129+
#. Reset the development kit.
130+
#. Observe in the terminal window that the application starts.
131+
This is indicated by output similar to the following (there is also a lot of additional information about the LTE connection):
132+
133+
.. code-block:: console
134+
135+
*** Booting My Application v1.0.0-f135319f826e ***
136+
*** Using nRF Connect SDK v3.1.99-f135319f826e ***
137+
*** Using Zephyr OS v4.2.99-be1a9fd0eeca ***
138+
[00:00:00.255,889] <inf> nrf_cloud_mqtt_fota: nRF Cloud MQTT FOTA Sample, version: 1.0.0
139+
[00:00:00.255,920] <inf> nrf_cloud_mqtt_fota: Reset reason: 0x1
140+
[00:00:00.828,735] <inf> nrf_cloud_credentials: Sec Tag: 16842753; CA: Yes, Client Cert: Yes, Private Key: Yes
141+
[00:00:00.828,765] <inf> nrf_cloud_credentials: CA Size: 1824, AWS: Likely, CoAP: Likely
142+
[00:00:00.828,796] <inf> nrf_cloud_mqtt_fota: nRF Cloud credentials detected!
143+
[00:00:00.829,589] <inf> nrf_cloud_mqtt_fota: Enabling connectivity...
144+
+CGEV: EXCE STATUS 0
145+
+CEREG: 2,"81A6","03229B10",7
146+
%MDMEV: PRACH CE-LEVEL 0
147+
+CSCON: 1
148+
+CGEV: ME PDN ACT 0
149+
%MDMEV: SEARCH STATUS 2
150+
+CEREG: 1,"81A6","03229B10",7,,,"11100000","11100000"
151+
[00:00:02.471,496] <inf> nrf_cloud_mqtt_fota: Connected to LTE
152+
+CGEV: IPV6 0
153+
[00:00:05.473,724] <inf> nrf_cloud_info: Device ID: 12345678-1234-5678-9abc-def012345678
154+
[00:00:05.474,395] <inf> nrf_cloud_info: IMEI: 359404230026479
155+
[00:00:05.474,575] <inf> nrf_cloud_info: UUID: 12345678-1234-5678-9abc-def012345678
156+
[00:00:05.474,822] <inf> nrf_cloud_info: Modem FW: mfw_nrf91x1_2.0.3
157+
[00:00:05.474,853] <inf> nrf_cloud_info: Protocol: MQTT
158+
[00:00:05.474,884] <inf> nrf_cloud_info: Download protocol: HTTPS
159+
[00:00:05.474,884] <inf> nrf_cloud_info: Sec tag: 16842753
160+
[00:00:05.474,914] <inf> nrf_cloud_info: Host name: mqtt.nrfcloud.com
161+
[00:00:05.474,945] <inf> nrf_cloud_mqtt_fota: Connecting to nRF Cloud...
162+
[00:00:08.681,701] <inf> nrf_cloud_mqtt_fota: Connection to nRF Cloud ready
163+
[00:00:08.681,793] <inf> nrf_cloud_info: Team ID: 12345678-1234-5678-9abc-def012345670
164+
165+
Dependencies
166+
************
167+
168+
This sample uses the following |NCS| libraries:
169+
170+
* :ref:`lib_nrf_cloud`
171+
* :ref:`lte_lc_readme`
172+
* :ref:`dk_buttons_and_leds_readme`
173+
* :ref:`modem_info_readme`
174+
* :ref:`lib_at_host`
175+
176+
In addition, it uses the following secure firmware component:
177+
178+
* :ref:`Trusted Firmware-M <ug_tfm>`
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
VERSION_MAJOR = 1
2+
VERSION_MINOR = 0
3+
PATCHLEVEL = 0
4+
VERSION_TWEAK = 0
5+
EXTRAVERSION =
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/ {
8+
chosen {
9+
nordic,pm-ext-flash = &gd25wb256;
10+
};
11+
};
12+
13+
/* External flash device is disabled by default */
14+
&gd25wb256 {
15+
status = "okay";
16+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/ {
8+
chosen {
9+
nordic,pm-ext-flash = &mx25r64;
10+
};
11+
};
12+
13+
/* External flash device is disabled by default */
14+
&mx25r64 {
15+
status = "okay";
16+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/ {
8+
chosen {
9+
nordic,pm-ext-flash = &gd25wb256;
10+
};
11+
};
12+
13+
/* External flash device is disabled by default */
14+
&gd25wb256 {
15+
status = "okay";
16+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/delete-node/ &gd25wb256;
8+
9+
/ {
10+
chosen {
11+
nordic,pm-ext-flash = &gd25lb256;
12+
};
13+
};
14+
15+
&gd25lb256 {
16+
status = "okay";
17+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
# Configuration file for Thingy:91 X.
8+
# This file is merged with prj.conf in the application folder, and options
9+
# set here will take precedence if they are present in both files.
10+
11+
# Enable external flash
12+
CONFIG_SPI_NOR_SFDP_DEVICETREE=y
13+
CONFIG_PM_OVERRIDE_EXTERNAL_DRIVER_CHECK=y
14+
CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y

0 commit comments

Comments
 (0)