Cellular: nRF Cloud MQTT cellular location
This sample demonstrates how to use the nRF Cloud MQTT 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_MQTT_CELL_DEFAULT_DOREPLY_VAL
(bool) Default value for the do_reply configuration flag
- CONFIG_MQTT_CELL_DEFAULT_FALLBACK_VAL
(bool) Default value for the fallback configuration flag
- CONFIG_MQTT_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_mqtt_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 My Application v1.0.0-4ac881908aba *** *** Using nRF Connect SDK v3.1.99-4ac881908aba *** *** Using Zephyr OS v4.2.99-8116dbcc6173 *** [00:00:00.292,480] <inf> nrf_cloud_mqtt_cell_location_sample: nRF Cloud MQTT Cellular Location Sample, version: 1.0.0 [00:00:00.630,432] <inf> nrf_cloud_mqtt_cell_location_sample: Connecting to LTE... +CGEV: EXCE STATUS 0 +CEREG: 2,"816B","0338D100",7 +CSCON: 1 +CGEV: ME PDN ACT 0 +CEREG: 1,"816B","0338D100",7,,,"11100000","11100000" [00:00:02.451,141] <inf> nrf_cloud_mqtt_cell_location_sample: Connected to network [00:00:02.451,324] <inf> nrf_cloud_mqtt_cell_location_sample: Waiting for current time %XTIME: "40","52115241146540","00" +CGEV: IPV6 0 [00:00:03.364,898] <inf> nrf_cloud_fota_common: Saved job: , type: 7, validate: 0, bl: 0x0 [00:00:03.477,264] <inf> nrf_cloud_info: Device ID: 7e699894-79b6-11f0-a2b4-db93a314a2aa [00:00:03.483,886] <inf> nrf_cloud_info: IMEI: 359400123456789 [00:00:03.575,439] <inf> nrf_cloud_info: UUID: 7e699894-79b6-11f0-a2b4-db93a314a2aa [00:00:03.581,115] <inf> nrf_cloud_info: Modem FW: mfw_nrf91x1_2.0.2-FOTA-TEST [00:00:03.581,146] <inf> nrf_cloud_info: Protocol: MQTT [00:00:03.581,176] <inf> nrf_cloud_info: Download protocol: HTTPS [00:00:03.581,207] <inf> nrf_cloud_info: Sec tag: 2147483650 [00:00:03.581,237] <inf> nrf_cloud_info: Host name: mqtt.nrfcloud.com +CEREG: 1,"816B","030D7C00",7,,,"11100000","11100000" [00:00:07.560,516] <inf> nrf_cloud_log: Changing cloud log level from:1 to:3 [00:00:07.560,546] <inf> nrf_cloud_log: Changing cloud logging enabled to:1 [00:00:08.033,996] <inf> nrf_cloud_mqtt_cell_location_sample: Connection to nRF Cloud ready [00:00:08.034,118] <inf> nrf_cloud_mqtt_cell_location_sample: Requesting location with the default configuration... [00:00:08.034,637] <inf> nrf_cloud_info: Team ID: 73cae6fb-3fe2-4119-ba53-e094be327b3e %NCELLMEAS: 0,"030D7C00","24201","816B",95,6400,454,58,15,7426,6400,14,58,15,0,6400,173,53,5,0,6400,239,51,1,0,6400,255,51,1,0,7380 %NCELLMEAS: 0,"030D7C00","24201","816B",95,7380,6400,454,56,11,7443,1,0 %NCELLMEAS: 0,"030D7C00","24201","816B",95,7380,6400,454,58,15,7506,1,4,6400,14,58,15,0,6400,173,53,5,0,6400,239,51,1,0,6400,255,51,-1,0 [00:00:08.764,373] <inf> nrf_cloud_mqtt_cell_location_sample: Cellular location request fulfilled with multi-cell [00:00:08.764,404] <inf> nrf_cloud_mqtt_cell_location_sample: Lat: 63.435616, Lon: 10.404310, Uncertainty: 1226 m [00:00:08.764,404] <inf> nrf_cloud_mqtt_cell_location_sample: Google maps URL: https://maps.google.com/?q=63.435616,10.404310 +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:
[00:00:03.698,913] <err> nrf_cloud_transport: Could not connect to nRF Cloud MQTT Broker mqtt.nrfcloud.com, port: 8883. err: -111 [00:00:03.698,974] <err> nrf_cloud_mqtt_cell_location_sample: NRF_CLOUD_EVT_TRANSPORT_CONNECT_ERROR: -9
Credentials are not registered or the device ID does not match the registered one:
[00:00:08.287,078] <err> nrf_cloud_transport: MQTT input error: -128 [00:00:08.287,139] <err> nrf_cloud_transport: Error disconnecting from cloud: -128 [00:00:08.287,170] <err> nrf_cloud_mqtt_cell_location_sample: NRF_CLOUD_EVT_TRANSPORT_DISCONNECTED
Dependencies
This sample uses the following nRF Connect SDK libraries:
In addition, it uses the following secure firmware component: