Cellular: nRF Cloud CoAP cellular location
This sample demonstrates how to use the nRF Cloud CoAP API for nRF Cloud’s cellular location service on your device.
Requirements
The sample supports the following development kits:
Hardware platforms |
PCA |
Board name |
|
|---|---|---|---|
PCA20065 |
|
||
PCA10153 |
|
||
PCA10090 |
|
||
PCA10171 |
|
For more security, it is recommended to use the */ns variant of the board target.
When built for this variant, the sample is configured to compile and run as a non-secure application using security by separation.
Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.
The sample requires an nRF Cloud account. Your device must be onboarded to nRF Cloud. If it is not, follow the instructions in Device on-boarding.
Overview
After the sample initializes and connects to the network, it sends a cell location request to nRF Cloud. For this purpose, the sample uses network data obtained from the Location library.
See the nRF Cloud Location Services documentation page for additional information.
Setup
You must onboard your device to nRF Cloud for this sample to function. You only need to do this once for each device. To onboard your device, install nRF Cloud Utils and follow the instructions in the README.
Configuration
See Configuring and building for information about how to permanently or temporarily change the configuration.
Configuration options
Check and configure the following Kconfig options for the sample:
- CONFIG_COAP_CELL_DEFAULT_DOREPLY_VAL
(bool) Default value for the do_reply configuration flag
- CONFIG_COAP_CELL_DEFAULT_FALLBACK_VAL
(bool) Default value for the fallback configuration flag
- CONFIG_COAP_CELL_DEFAULT_HICONF_VAL
(bool) Default value for the hi_conf configuration flag
Sending traces over UART on an nRF91 Series DK
To send modem traces over UART on an nRF91 Series DK, configuration must be added for the UART device in the devicetree and Kconfig. This is done by adding the modem trace UART snippet when building and programming.
Use the Cellular Monitor app for capturing and analyzing modem traces.
TF-M logging must use the same UART as the application. For more details, see shared TF-M logging.
Building and running
This sample can be found under samples/cellular/nrf_cloud_coap_cell_location in the nRF Connect SDK folder structure.
For more security, it is recommended to use the */ns variant of the board target (see the Requirements section above.)
When built for this variant, the sample is configured to compile and run as a non-secure application using security by separation.
Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.
To build the sample, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.
Note
When building repository applications in the SDK repositories, building with sysbuild is enabled by default.
If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild parameter to every build command or configure west to always use it.
Testing
After programming the sample to your development kit, complete the following steps to test it:
Connect the kit to the computer using a USB cable. The kit is assigned a serial port. Serial ports are referred to as COM ports on Windows, /dev/ttyACM devices on Linux, and /dev/tty devices on macOS. To list Nordic Semiconductor devices connected to your computer together with their serial ports, open a terminal and run the
nrfutil device listcommand. Alternatively, check your operating system’s device manager or its equivalent.Connect to the kit with a terminal emulator (for example, the Serial Terminal app). See Testing and optimization for the required settings and steps.
Reset the development kit.
Observe in the terminal window that the application starts. This is indicated by output similar to the following (there is also a lot of additional information about the LTE connection):
*** Booting nRF Connect SDK v3.1.99-34fcb6d9589a *** *** Using Zephyr OS v4.2.99-de567402f088 *** Attempting to boot slot 0. Attempting to boot from address 0x8200. I: Trying to get Firmware version I: Verifying signature against key 0. I: Hash: 0x3e...f9 I: Firmware signature verified. Firmware version 2 �[00:00:00.254,730] <inf> spi_nor: GD25LE255E@0: 32 MiBy flash *** Booting My Application v1.0.0-34fcb6d9589a *** *** Using nRF Connect SDK v3.1.99-34fcb6d9589a *** *** Using Zephyr OS v4.2.99-de567402f088 *** [00:00:00.292,755] <inf> nrf_cloud_coap_cell_location_sample: nRF Cloud CoAP Cellular Location Sample, version: 1.0.0 [00:00:00.631,042] <inf> nrf_cloud_coap_cell_location_sample: Connecting to LTE... +CGEV: EXCE STATUS 0 +CEREG: 2,"8169","014A0305",7 +CSCON: 1 +CGEV: ME PDN ACT 0 +CEREG: 1,"8169","014A0305",7,,,"11100000","11100000" [00:00:02.690,887] <inf> nrf_cloud_coap_cell_location_sample: Connected to network +CGEV: IPV6 0 [00:00:02.813,446] <inf> nrf_cloud_info: Device ID: 7e699894-79b6-11f0-a2b4-db93a314a2aa [00:00:02.815,460] <inf> nrf_cloud_info: IMEI: 359400123456789 [00:00:02.935,058] <inf> nrf_cloud_info: UUID: 7e699894-79b6-11f0-a2b4-db93a314a2aa [00:00:02.935,516] <inf> nrf_cloud_info: Modem FW: mfw_nrf91x1_2.0.2-FOTA-TEST [00:00:02.935,546] <inf> nrf_cloud_info: Protocol: CoAP [00:00:02.935,577] <inf> nrf_cloud_info: Download protocol: HTTPS [00:00:02.935,607] <inf> nrf_cloud_info: Sec tag: 2147483650 [00:00:02.935,638] <inf> nrf_cloud_info: CoAP JWT Sec tag: 2147483650 [00:00:02.935,668] <inf> nrf_cloud_info: Host name: coap.nrfcloud.com [00:00:04.527,893] <inf> nrf_cloud_coap_transport: Request authorization with JWT [00:00:04.806,762] <inf> nrf_cloud_coap_transport: Authorization result_code: 2.01 [00:00:04.806,884] <inf> nrf_cloud_coap_transport: Authorized [00:00:04.807,067] <inf> nrf_cloud_coap_transport: DTLS CID is active [00:00:05.356,933] <inf> nrf_cloud_coap_cell_location_sample: Requesting location with the default configuration... %NCELLMEAS: 0,"014A0305","24201","8169",80,6400,105,53,20,4791,6400,247,52,18,0,6400,106,50,14,0,4659 %NCELLMEAS: 0,"014A0305","24201","8169",80,4659,6400,105,50,16,4758,1,0 %NCELLMEAS: 0,"014A0305","24201","8169",80,4659,6400,105,50,16,4758,1,0 [00:00:05.611,999] <inf> nrf_cloud_coap_cell_location_sample: Cellular location request fulfilled with multi-cell [00:00:05.612,030] <inf> nrf_cloud_coap_cell_location_sample: Lat: 63.423117, Lon: 10.436068, Uncertainty: 1618 m [00:00:05.612,060] <inf> nrf_cloud_coap_cell_location_sample: Google maps URL: https://maps.google.com/?q=63.423117,10.436068 +CSCON: 0
Troubleshooting
If you are not getting the output similar to the one in Testing, check the following potential issues:
- The network carrier does not provide date and time
The sample requires the network carrier to provide date and time to the modem. Without a valid date and time, the modem cannot generate JWTs with an expiration time.
Credentials are missing on the configured sec tag:
Note
CoAP connections require a different root CA certificate compared to MQTT. It is possible to provision both certificates on the same sec tag.
[00:00:03.067,291] <err> nrf_cloud_coap_transport: Could not connect to nRF Cloud CoAP server coap.nrfcloud.com, port: 5684. err: -111
[00:00:03.067,321] <err> nrf_cloud_coap_cell_location_sample: Connecting to nRF Cloud failed, error: -111
Credentials are not registered or the device ID does not match the registered one:
[00:00:05.081,756] <err> nrf_cloud_coap_transport: Device not authenticated; reconnection required. [00:00:05.081,787] <inf> nrf_cloud_coap_transport: Authorization result_code: 4.01 [00:00:05.583,435] <err> nrf_cloud_coap_cell_location_sample: Connecting to nRF Cloud failed, error: -13
Dependencies
This sample uses the following nRF Connect SDK libraries:
In addition, it uses the following secure firmware component: