Skip to content

Commit 734f2ae

Browse files
maxd-nordicnordicjm
authored andcommitted
samples: cellular: add nrf_cloud_coap_cell_location sample
This sample demonstrates how to use the nRF Cloud CoAP API to request position using cellular network information. Signed-off-by: Maximilian Deubel <[email protected]>
1 parent 5a04025 commit 734f2ae

File tree

9 files changed

+1002
-3
lines changed

9 files changed

+1002
-3
lines changed

doc/nrf/links.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,7 @@
14801480
.. _`nRF Cloud Location Services`: https://api.nrfcloud.com/v1#tag/Location-Services
14811481
.. _`nRF Cloud REST API ProvisionDevices`: https://api.nrfcloud.com/v1#tag/IP-Devices/operation/ProvisionDevices
14821482
.. _`nRF Cloud RegisterPublicKeys Endpoint`: https://api.nrfcloud.com/v1/#operation/RegisterPublicKeys
1483+
.. _`nRF Cloud CoAP API`: https://docs.nordicsemi.com/bundle/nrf-cloud/page/APIs/CoAP/CoAPOverview.html
14831484

14841485
.. _`Bulk Onboard Devices`:
14851486
.. _`nRF Cloud Portal Bulk Onboard Devices`: https://nrfcloud.com/#/add-device/bulk

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,11 @@ Bluetooth Fast Pair samples
261261
Cellular samples
262262
----------------
263263

264-
* :ref:`nrf_cloud_rest_cell_location` sample:
264+
* Added the :ref:`nrf_cloud_coap_cell_location` sample to demonstrate how to use the `nRF Cloud CoAP API`_ for nRF Cloud's cellular location service.
265265

266-
* Added:
266+
* :ref:`nrf_cloud_rest_cell_location` sample:
267267

268-
* Runtime setting of the log level for the nRF Cloud logging feature.
268+
* Added runtime setting of the log level for the nRF Cloud logging feature.
269269

270270
Cryptography samples
271271
--------------------
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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_coap_cell_location_sample)
11+
12+
target_sources(app PRIVATE src/main.c)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
menu "nRF Cloud CoAP Cellular Location Sample"
8+
9+
config COAP_CELL_GCI_COUNT
10+
int "Maximum number of cells to be searched"
11+
range 2 15
12+
default 5
13+
14+
config COAP_CELL_CHANGE_CONFIG
15+
bool "Change the location request configuration on button press"
16+
default y
17+
help
18+
After attempting both single and multi cell location requests,
19+
try the next combination of the struct nrf_cloud_location_config
20+
hi_conf and fallback flags. The do_reply flag is not modified.
21+
22+
config COAP_CELL_DEFAULT_DOREPLY_VAL
23+
bool "Default value for the do_reply configuration flag"
24+
default y
25+
26+
config COAP_CELL_DEFAULT_FALLBACK_VAL
27+
bool "Default value for the fallback configuration flag"
28+
default y
29+
30+
config COAP_CELL_DEFAULT_HICONF_VAL
31+
bool "Default value for the hi_conf configuration flag"
32+
33+
config COAP_CELL_SEND_DEVICE_STATUS
34+
bool "Send device status to nRF Cloud on initial connection"
35+
default y
36+
37+
module = NRF_CLOUD_COAP_CELL_LOCATION_SAMPLE
38+
module-str = nRF Cloud CoAP Cellular Location Sample
39+
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
40+
41+
endmenu
42+
43+
menu "Zephyr Kernel"
44+
source "Kconfig.zephyr"
45+
endmenu
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
.. _nrf_cloud_coap_cell_location:
2+
3+
Cellular: nRF Cloud CoAP cellular location
4+
##########################################
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
This sample demonstrates how to use the `nRF Cloud CoAP API`_ for nRF Cloud's cellular location service on your device.
11+
12+
Requirements
13+
************
14+
15+
The sample supports the following development kits:
16+
17+
.. table-from-sample-yaml::
18+
19+
.. include:: /includes/tfm.txt
20+
21+
The sample requires an `nRF Cloud`_ account.
22+
Your device must be onboarded to nRF Cloud.
23+
If it is not, follow the instructions in `Device on-boarding <nrf_cloud_coap_cell_location_onboarding>`_.
24+
25+
.. note::
26+
This sample requires modem firmware v1.3.x or later for an nRF9160 DK, or modem firmware v2.x.x for the nRF9161 and nRF9151 DKs.
27+
28+
Overview
29+
********
30+
31+
The sample can work in two modes: single-cell mode and multi-cell mode.
32+
33+
After the sample initializes and connects to the network, it enters the single-cell mode and sends a single-cell location request to nRF Cloud.
34+
For this purpose, the sample uses network data obtained from the :ref:`modem_info_readme` library.
35+
In the multi-cell mode, the sample requests for neighbor cell measurement using the :ref:`lte_lc_readme` library.
36+
37+
If the modem provides neighbor cell data, the sample sends a multi-cell location request to nRF Cloud.
38+
Otherwise, the request is single-cell.
39+
40+
In either mode, the sample sends a new location request if a change in cell ID is detected.
41+
42+
See the `nRF Cloud Location Services documentation`_ for additional information.
43+
44+
User interface
45+
**************
46+
47+
Button 1:
48+
Toggle between the single-cell and multi-cell mode.
49+
50+
.. _nrf_cloud_coap_cell_location_onboarding:
51+
52+
Setup
53+
=====
54+
55+
You must onboard your device to nRF Cloud for this sample to function.
56+
You only need to do this once for each device.
57+
To onboard your device, install `nRF Cloud Utils`_ and follow the instructions in the README.
58+
59+
Configuration
60+
*************
61+
62+
|config|
63+
64+
Configuration options
65+
=====================
66+
67+
Check and configure the following Kconfig options for the sample:
68+
69+
.. _CONFIG_COAP_CELL_CHANGE_CONFIG:
70+
71+
CONFIG_COAP_CELL_CHANGE_CONFIG - Enable changing request configuration
72+
Set this to use the next combination of ``hi_conf`` and ``fallback`` flags after performing both single- and multi-cell location requests.
73+
74+
.. _CONFIG_COAP_CELL_DEFAULT_DOREPLY_VAL:
75+
76+
CONFIG_COAP_CELL_DEFAULT_DOREPLY_VAL - Enable return of location from cloud
77+
If enabled, request the cloud to return the location information.
78+
79+
.. _CONFIG_COAP_CELL_DEFAULT_FALLBACK_VAL:
80+
81+
CONFIG_COAP_CELL_DEFAULT_FALLBACK_VAL - Enable fallback to coarse location
82+
If enabled and the location of the cell tower or Wi-Fi® access points cannot be found, return area-level location based on the cellular tracking area code.
83+
Otherwise an error will be returned indicating location is not known.
84+
85+
.. _CONFIG_COAP_CELL_DEFAULT_HICONF_VAL:
86+
87+
CONFIG_COAP_CELL_DEFAULT_HICONF_VAL - Enable high-confidence result
88+
Enable a 95% confidence interval for the location, instead of the default 68%.
89+
90+
.. _CONFIG_COAP_CELL_SEND_DEVICE_STATUS:
91+
92+
CONFIG_COAP_CELL_SEND_DEVICE_STATUS - Send device status
93+
Send device status to nRF Cloud on initial connection.
94+
95+
.. include:: /libraries/modem/nrf_modem_lib/nrf_modem_lib_trace.rst
96+
:start-after: modem_lib_sending_traces_UART_start
97+
:end-before: modem_lib_sending_traces_UART_end
98+
99+
Building and running
100+
********************
101+
102+
.. |sample path| replace:: :file:`samples/cellular/nrf_cloud_coap_cell_location`
103+
104+
.. include:: /includes/build_and_run_ns.txt
105+
106+
Testing
107+
=======
108+
109+
|test_sample|
110+
111+
#. |connect_kit|
112+
#. |connect_terminal|
113+
#. Reset the development kit.
114+
#. Observe in the terminal window that the application starts.
115+
This is indicated by output similar to the following (there is also a lot of additional information about the LTE connection):
116+
117+
.. code-block:: console
118+
119+
*** Booting nRF Connect SDK v3.0.99-065f86a42eaa ***
120+
*** Using Zephyr OS v4.1.99-82973b4f6d2a ***
121+
Attempting to boot slot 0.
122+
Attempting to boot from address 0x8200.
123+
I: Trying to get Firmware version
124+
I: Verifying signature against key 0.
125+
I: Hash: 0x3e...f9
126+
I: Firmware signature verified.
127+
Firmware version 2
128+
�[00:00:00.254,821] <inf> spi_nor: GD25LE255E@0: 32 MiBy flash
129+
*** Booting My Application v1.0.0-065f86a42eaa ***
130+
*** Using nRF Connect SDK v3.0.99-065f86a42eaa ***
131+
*** Using Zephyr OS v4.1.99-82973b4f6d2a ***
132+
[00:00:00.292,907] <inf> nrf_cloud_coap_cell_location_sample: nRF Cloud CoAP Cellular Location Sample, version: 1.0.0
133+
[00:00:00.715,637] <inf> nrf_cloud_coap_cell_location_sample: Device ID: 7e699894-79b6-11f0-a2b4-db93a314a2aa
134+
[00:00:00.721,313] <inf> nrf_cloud_coap_cell_location_sample: Using LTE LC neighbor search type GCI extended complete for 5 cells
135+
[00:00:01.023,040] <inf> nrf_cloud_credentials: Sec Tag: 16842753; CA: Yes, Client Cert: Yes, Private Key: Yes
136+
[00:00:01.023,101] <inf> nrf_cloud_credentials: CA Size: 1824, AWS: Likely, CoAP: Likely
137+
[00:00:01.023,101] <inf> nrf_cloud_coap_cell_location_sample: nRF Cloud credentials detected!
138+
[00:00:01.023,132] <inf> nrf_cloud_coap_cell_location_sample: Enabling connectivity...
139+
+CGEV: EXCE STATUS 0
140+
+CEREG: 2,"0910","020A6B0C",7
141+
%MDMEV: PRACH CE-LEVEL 0
142+
+CSCON: 1
143+
[00:00:02.995,330] <inf> nrf_cloud_coap_cell_location_sample: RRC mode: connected
144+
+CGEV: ME PDN ACT 0,0
145+
+CNEC_ESM: 50,0
146+
%MDMEV: SEARCH STATUS 2
147+
+CEREG: 5,"0910","020A6B0C",7,,,"11100000","11100000"
148+
[00:00:07.840,423] <inf> nrf_cloud_coap_cell_location_sample: Connected to network
149+
[00:00:07.840,515] <inf> nrf_cloud_coap_cell_location_sample: Waiting for modem to acquire network time...
150+
[00:00:10.841,247] <inf> nrf_cloud_coap_cell_location_sample: Network time obtained
151+
[00:00:10.841,308] <inf> nrf_cloud_info: Device ID: 7e699894-79b6-11f0-a2b4-db93a314a2aa
152+
[00:00:10.841,857] <inf> nrf_cloud_info: IMEI: 359400123456789
153+
[00:00:10.941,680] <inf> nrf_cloud_info: UUID: 7e699894-79b6-11f0-a2b4-db93a314a2aa
154+
[00:00:10.948,211] <inf> nrf_cloud_info: Modem FW: mfw_nrf91x1_2.0.2
155+
[00:00:10.948,242] <inf> nrf_cloud_info: Protocol: CoAP
156+
[00:00:10.948,272] <inf> nrf_cloud_info: Download protocol: HTTPS
157+
[00:00:10.948,303] <inf> nrf_cloud_info: Sec tag: 16842753
158+
[00:00:10.948,303] <inf> nrf_cloud_info: CoAP JWT Sec tag: 16842753
159+
[00:00:10.948,333] <inf> nrf_cloud_info: Host name: coap.nrfcloud.com
160+
[00:00:12.721,099] <inf> nrf_cloud_coap_transport: Request authorization with JWT
161+
[00:00:12.986,877] <inf> nrf_cloud_coap_transport: Authorization result_code: 2.01
162+
[00:00:12.986,999] <inf> nrf_cloud_coap_transport: Authorized
163+
[00:00:12.987,213] <inf> nrf_cloud_coap_transport: DTLS CID is active
164+
[00:00:13.716,003] <inf> nrf_cloud_coap_cell_location_sample: Device status sent to nRF Cloud
165+
[00:00:13.716,033] <inf> nrf_cloud_coap_cell_location_sample: Getting current cell info...
166+
[00:00:13.725,494] <inf> nrf_cloud_coap_cell_location_sample: Current cell info: Cell ID: 34237196, TAC: 2320, MCC: 242, MNC: 2
167+
[00:00:13.725,524] <inf> nrf_cloud_coap_cell_location_sample: Performing single-cell request
168+
[00:00:13.725,524] <inf> nrf_cloud_coap_cell_location_sample: Request configuration:
169+
[00:00:13.725,555] <inf> nrf_cloud_coap_cell_location_sample: High confidence interval = false
170+
[00:00:13.725,616] <inf> nrf_cloud_coap_cell_location_sample: Fallback to rough location = true
171+
[00:00:13.725,646] <inf> nrf_cloud_coap_cell_location_sample: Reply with result = true
172+
[00:00:13.991,180] <inf> nrf_cloud_coap_cell_location_sample: Cellular location request fulfilled with single-cell
173+
[00:00:13.991,210] <inf> nrf_cloud_coap_cell_location_sample: Lat: 63.423740, Lon: 10.435896, Uncertainty: 1056 m
174+
175+
Troubleshooting
176+
===============
177+
178+
If you are not getting the output similar to the one in `Testing`_, check the following potential issues:
179+
180+
The network carrier does not provide date and time
181+
The sample requires the network carrier to provide date and time to the modem.
182+
Without a valid date and time, the modem cannot generate JWTs with an expiration time.
183+
184+
Dependencies
185+
************
186+
187+
This sample uses the following |NCS| libraries:
188+
189+
* :ref:`lib_nrf_cloud`
190+
* :ref:`lib_nrf_cloud_coap`
191+
* :ref:`lib_modem_jwt`
192+
* :ref:`lte_lc_readme`
193+
* :ref:`modem_info_readme`
194+
* :ref:`dk_buttons_and_leds_readme`
195+
196+
In addition, it uses the following secure firmware component:
197+
198+
* :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: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Sample
2+
CONFIG_NRF_CLOUD_COAP_CELL_LOCATION_SAMPLE_LOG_LEVEL_INF=y
3+
4+
# nRF Cloud CoAP
5+
CONFIG_NRF_CLOUD=y
6+
CONFIG_NRF_CLOUD_CLIENT_ID_SRC_INTERNAL_UUID=y
7+
CONFIG_MODEM_JWT=y
8+
CONFIG_POSIX_API=y
9+
CONFIG_NRF_CLOUD_CHECK_CREDENTIALS=y
10+
CONFIG_NRF_CLOUD_COAP=y
11+
CONFIG_NRF_CLOUD_COAP_DOWNLOADS=n
12+
13+
# AT Host
14+
CONFIG_AT_HOST_LIBRARY=y
15+
CONFIG_NRF_MODEM_LIB=y
16+
CONFIG_AT_MONITOR_HEAP_SIZE=4096
17+
CONFIG_AT_HOST_STACK_SIZE=2048
18+
19+
# Button support
20+
CONFIG_DK_LIBRARY=y
21+
CONFIG_GPIO=y
22+
23+
# Networking
24+
CONFIG_NETWORKING=y
25+
CONFIG_NET_SOCKETS=y
26+
CONFIG_NET_SOCKETS_OFFLOAD=y
27+
28+
# Enable LTE Connectivity using Connection Manager
29+
CONFIG_NET_IPV4=y
30+
CONFIG_NET_IPV6=y
31+
CONFIG_NET_IPV6_NBR_CACHE=n
32+
CONFIG_NET_IPV6_MLD=n
33+
CONFIG_NET_CONNECTION_MANAGER=y
34+
CONFIG_NRF_MODEM_LIB=y
35+
CONFIG_NRF_MODEM_LIB_NET_IF=y
36+
CONFIG_NRF_MODEM_LIB_NET_IF_AUTO_DOWN=y
37+
CONFIG_NRF_MODEM_LIB_NET_IF_DOWN_DEFAULT_LTE_DISCONNECT=y
38+
CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE=1024
39+
CONFIG_NET_MGMT_EVENT_STACK_SIZE=1024
40+
41+
# Modem/LTE Link
42+
CONFIG_LTE_LINK_CONTROL=y
43+
CONFIG_LTE_LC_NEIGHBOR_CELL_MEAS_MODULE=y
44+
45+
# Modem info
46+
CONFIG_MODEM_INFO=y
47+
CONFIG_MODEM_INFO_ADD_DEVICE=y
48+
CONFIG_MODEM_INFO_ADD_NETWORK=y
49+
CONFIG_MODEM_INFO_ADD_DATE_TIME=n
50+
CONFIG_MODEM_INFO_ADD_SIM=y
51+
CONFIG_MODEM_INFO_ADD_SIM_ICCID=n
52+
CONFIG_MODEM_INFO_ADD_SIM_IMSI=n
53+
54+
# System
55+
CONFIG_HEAP_MEM_POOL_SIZE=8192
56+
CONFIG_MAIN_STACK_SIZE=8192
57+
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=8192
58+
CONFIG_ASSERT=y
59+
CONFIG_REBOOT=y
60+
CONFIG_FPU=y
61+
CONFIG_PICOLIBC_IO_FLOAT=y
62+
CONFIG_EVENTS=y
63+
64+
# Logging
65+
CONFIG_LOG=y
66+
CONFIG_LOG_MODE_DEFERRED=y
67+
CONFIG_UART_INTERRUPT_DRIVEN=y
68+
69+
# LTE Link Control
70+
CONFIG_LTE_LINK_CONTROL=y
71+
CONFIG_LTE_LC_PSM_MODULE=y
72+
73+
# CoAP Client
74+
CONFIG_COAP_CLIENT_BLOCK_SIZE=1024
75+
CONFIG_COAP_CLIENT_STACK_SIZE=6144
76+
CONFIG_COAP_CLIENT_THREAD_PRIORITY=0
77+
CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE=40
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
sample:
2+
name: nRF Cloud CoAP cellular location
3+
tests:
4+
sample.cellular.nrf_cloud_coap_cell_pos:
5+
sysbuild: true
6+
build_only: true
7+
integration_platforms:
8+
- nrf9151dk/nrf9151/ns
9+
- nrf9160dk/nrf9160/ns
10+
- nrf9161dk/nrf9161/ns
11+
- thingy91x/nrf9151/ns
12+
platform_allow:
13+
- nrf9151dk/nrf9151/ns
14+
- nrf9160dk/nrf9160/ns
15+
- nrf9161dk/nrf9161/ns
16+
- thingy91x/nrf9151/ns
17+
tags:
18+
- ci_build
19+
- sysbuild
20+
- ci_samples_cellular

0 commit comments

Comments
 (0)