Cellular: nRF Device provisioning

This sample demonstrates how to use the nRF Cloud device provisioning service on your device.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Build target

nRF9161 DK

PCA10153

nrf9161dk

nrf9161dk/nrf9161/ns

nRF9151 DK

PCA10171

nrf9151dk

nrf9151dk/nrf9151/ns

When built for an _ns build target, the sample is configured to compile and run as a non-secure application with Cortex-M Security Extensions enabled. Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.

The sample requires that the device’s private key is installed on the device and the associated device UUID is obtained from the Identity Service.

Note

This sample requires modem firmware v2.0.0 or later.

Overview

The sample shows how the device performs the following actions:

  • Connects to nRF Cloud Provisioning Service.

  • Fetches available device-specific provisioning configuration.

  • Decodes the commands.

  • Acts on any AT commands, if available.

  • Reports the results back to the server. In the case of an error, stops processing the commands at the first error and reports it back to server.

  • Sends FINISHED response if all the previous commands are executed without errors provided and FINISHED is one of the set provisioning commands.

User interface

Device side interaction is not required. You must define the provisioning configuration at the server side. See nRF Cloud provisioning configuration.

Configuration

See Configuring and building an application for information about how to permanently or temporarily change the configuration.

Configuration options

Check and configure the following configuration options for the sample:

CONFIG_NRF_PROVISIONING_ROOT_CA_SEC_TAG

Root CA security tag for the nRF Cloud Provisioning Service. Needs to be set explicitly and if not, the compilation fails.

CONFIG_RF_PROVISIONING_RX_BUF_S

Configures the response payload buffer size.

CONFIG_NRF_PROVISIONING_TX_BUF_SZ

Configures the command request buffer size.

HTTP options

CONFIG_NRF_PROVISIONING_HTTP_HOSTNAME

Configures the hostname of the nRF Cloud Provisioning Service.

CONFIG_NRF_PROVISIONING_HTTP_PORT

Configures the HTTP port of the nRF Cloud Provisioning Service.

CONFIG_NRF_PROVISIONING_HTTP_TIMEOUT_MS

Configures the HTTP timeout.

CoAP options

CONFIG_NRF_PROVISIONING_COAP_HOSTNAME

Configures the hostname of the nRF Cloud Provisioning Service.

CONFIG_NRF_PROVISIONING_COAP_PORT

Configures the CoAP port of the nRF Cloud Provisioning Service.

CONFIG_NRF_PROVISIONING_COAP_DTLS_SESSION_CACHE

Enables DTLS session cache.

Configuration files

The sample provides predefined configuration files for typical use cases.

The following files are available:

  • prj.conf - Standard default configuration file.

  • overlay-coap.conf - Enables CoAP transfer protocol support.

  • overlay-at_shell.conf - Enables writing of large certificates from AT shell.

Building and running

This sample can be found under samples/cellular/nrf_provisioning in the nRF Connect SDK folder structure.

When built as firmware image for the _ns build target, the sample has Cortex-M Security Extensions (CMSE) enabled and separates the firmware between Non-Secure Processing Environment (NSPE) and Secure Processing Environment (SPE). Because of this, it automatically includes the Trusted Firmware-M (TF-M). To read more about CMSE, see Processing environments.

To build the sample with Visual Studio Code, follow the steps listed on the How to build an application page in the nRF Connect for VS Code extension documentation. See Configuring and building an application for other building scenarios, Programming an application for programming steps, and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.

Testing

After programming the sample to your development kit, complete the following steps to test it:

  1. Connect the kit to the computer using a USB cable. The kit is assigned a COM port (Windows) or ttyACM device (Linux), which is visible in the Device Manager.

  2. Connect to the kit with a terminal emulator (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.

  3. Add a provisioning configuration using the nRF Cloud Provisioning Service. See nRF Cloud provisioning configuration.

  4. Power on or reset your device.

  5. Observe that the sample starts and connects to the LTE network.

  6. Observe that provisioning pauses and resumes while fetching and executing provisioning commands.

Sample output

The following is an example output of the sample when there is no provisioning configuration on the server side:

<inf> nrf_provisioning_sample: Establishing LTE link ...
<inf> nrf_provisioning_sample: Provisioning started
<inf> nrf_provisioning_http: Requesting commands
<inf> nrf_provisioning_http: Connected
<inf> nrf_provisioning_http: No more commands to process on server side
<inf> nrf_provisioning_sample: Provisioning stopped

The following is an example output when the sample is processing commands from the server:

<inf> nrf_provisioning_sample: Establishing LTE link ...
<inf> nrf_provisioning_sample: Provisioning started
<inf> nrf_provisioning_http: Requesting commands
<inf> nrf_provisioning_http: Connected
<inf> nrf_provisioning_http: Processing commands
<inf> nrf_provisioning: Disconnected from network - provisioning paused
<inf> nrf_provisioning: Connected; home network - provisioning resumed
<inf> nrf_provisioning_sample: Modem connection restored
<inf> nrf_provisioning_sample: Waiting for modem to acquire network time...
<inf> nrf_provisioning_sample: Network time obtained
<inf> nrf_provisioning_http: Sending response to server
<inf> nrf_provisioning_http: Requesting commands
<inf> nrf_provisioning_http: Connected
<inf> nrf_provisioning_http: No more commands to process on server side
<inf> nrf_provisioning_sample: Provisioning stopped
<inf> nrf_provisioning_sample: Provisioning done, rebooting...
<inf> nrf_provisioning: Disconnected from network - provisioning paused

Dependencies

This sample uses the following nRF Connect SDK libraries:

It uses the following sdk-nrfxlib library: