Skip to main content

Scripts and utilities for working with the nRF Cloud

Project description

nRF Cloud Utils

nRF Cloud Utils is a script collection to make it easier to interface with nRF Cloud.

The scripts in this repository mainly use endpoints in the REST API.

See also the official nRF Cloud documentation.

Table of Contents

Install

Run the following command to use this package as a dependency:

pip3 install nrfcloud-utils

Requirements

  1. Create an account in nrfcloud.com.
  2. Retrieve your API key. You can find it in your nRF Cloud User Account page.
  3. To simplify the use of the scripts, you can declare your API key as an environment variable in your terminal. This way, you won't need to repeatedly type it in each command. Here's how to do it:
export API_KEY=<your_api_key>

Replace <your_api_key> with your actual API key. If you don't choose this path, take note of your API key, you will need it soon. Note that if you are part of multiple teams on nRF Cloud, the API key will be different for each one.

  1. Depending on your goal, you'll need to configure your nRF Connect SDK project with the following libraries:
  1. When compiling with the nRF Cloud Libraries, make sure to add the next Kconfig options:

    # Enable modem-based JSON Web Token (JWT) generation required for nRF Cloud authentication
    CONFIG_MODEM_JWT=y
    
    # Configure the nRF Cloud library to use the device's internal UUID as the client ID
    CONFIG_NRF_CLOUD_CLIENT_ID_SRC_INTERNAL_UUID=y
    
    # Define the modem security tag where nRF Cloud credentials will be stored (16842753 is the standard tag used by Nordic examples)
    CONFIG_NRF_CLOUD_SEC_TAG=16842753
    

Failure to include these settings will prevent the device from connecting to nRF Cloud.

How-To: Registering devices quickly

Start by creating a local certificate authority (CA). Its contents won't be checked, but you need one to make certificates for your devices. Optionally, pass options to the script to specify owner information.

create_ca_cert

Now, you should have three .pem files containing the key pair and the CA certificate of your CA. The files have a unique prefix.

The fastest way to get your device registered is using the Device Credentials Installer:

device_credentials_installer -d --ca *_ca.pem --ca-key *_prv.pem --coap --verify

Upon success, you can find an onboard.csv file with information about your device. We need this file to register the certificate with your account. If you encounter a No device found error, you might need to specify the serial port using the --port option.

Finally, add the device to your account with the Onboarding script:

nrf_cloud_onboard --api-key $API_KEY --csv onboard.csv

You can also install credentials on many devices in a row using the --append option and add the bulk onboard.csv to your account with the same command.

Congratulations! You have successfully registered your device to nRF Cloud, you should be able to visualize it on the Devices panel.

Advanced Usage

For a more detailed overview of the scripts and their capabilities, refer to the Advanced Usage Guide. This guide provides in-depth instructions on leveraging advanced features, including the use of the Provisioning Service for remote provisioning of devices, as an alternative to local provisioning.

Development installation

Clone the repository:

git clone https://github.com/nRFCloud/utils.git nrfcloud-utils
cd nrfcloud-utils

For development mode, you need poetry:

curl -sSL https://install.python-poetry.org | python3 -

Make sure poetry is in your PATH. If you're using bash:

echo 'export PATH=/home/$USER/.local/bin:$PATH' | tee -a ~/.bashrc
source ~/.bashrc

Install package dependencies, development dependencies, and the nrfcloud-utils into poetry's internal virtual environment:

poetry install

Test

Unit tests are included in the tests folder. Each test script corresponds to a script in the sources. Static files used in the tests are put in the tests/fixtures folder. Running the tests depends on a development installation.

poetry run pytest

Check coverage

poetry run pytest --cov=. tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nrfcloud_utils-2.0.0.tar.gz (44.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nrfcloud_utils-2.0.0-py3-none-any.whl (54.1 kB view details)

Uploaded Python 3

File details

Details for the file nrfcloud_utils-2.0.0.tar.gz.

File metadata

  • Download URL: nrfcloud_utils-2.0.0.tar.gz
  • Upload date:
  • Size: 44.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.12 Linux/6.11.0-1012-azure

File hashes

Hashes for nrfcloud_utils-2.0.0.tar.gz
Algorithm Hash digest
SHA256 0271534cd1fb0f4886a0ff6d28207fa62a589ef6b91b3ca7f2a9a9cf82a007ff
MD5 044e5b1dc41758e928fe7eac9c739832
BLAKE2b-256 a416d80dd81a49c8069571cccfbe7e6a68ab150f32abe292941e1038b9b905c6

See more details on using hashes here.

File details

Details for the file nrfcloud_utils-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: nrfcloud_utils-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 54.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.12 Linux/6.11.0-1012-azure

File hashes

Hashes for nrfcloud_utils-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e07b7388e333e0d89bc7c95c2ae19feefc6dbfcdd1c0f219b63258780712b84d
MD5 58d006ebe49aae05c4d4bb4f79438da5
BLAKE2b-256 df04b57bb5d8920a1a329c1d11f97ff0c8a245924b481e5c5ed524b04739fa11

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page