Cellular: GNSS

This sample demonstrates how to use the Global Navigation Satellite System to control the GNSS module. It also shows how to improve fix speed and accuracy with the nRF Cloud A-GNSS library and how to use the nRF Cloud P-GPS library. Assistance data is downloaded from nRF Cloud using nRF Cloud’s REST-based device API.


The sample supports the following development kits:

Hardware platforms


Board name

Build target

nRF9161 DK




nRF9160 DK




nRF9151 DK




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 first initializes the GNSS module. Then it handles events from the interface, reads the associated data and outputs information to the console. Because NMEA data needs to be read as soon as an NMEA event is received, a Zephyr message queue is used for buffering the NMEA strings. The event handler function reads the received NMEA strings and puts those into the message queue. The consumer loop reads from the queue and outputs the strings to the console.

Operation modes

The sample supports different operation modes:

  • Continuous

  • Periodic

  • Time-to-first-fix (TTFF) test

By default, the sample runs in continuous tracking mode. In continuous mode, GNSS tries to acquire a fix once a second.

In periodic mode, fixes are acquired periodically with the set interval.

In TTFF test mode, the sample acquires fixes periodically and calculates the TTFF for each fix. You can use the TTFF test mode without assistance or with any supported assistance method. You can also configure it to perform cold starts, where the stored data is deleted from GNSS before each start. If you enable assistance with cold starts, new assistance data is also downloaded and injected to GNSS before each start.

Output modes

The sample supports two output modes:

  • Position, Velocity, and Time (PVT) and NMEA

  • NMEA-only

By default, the sample displays information from both PVT and NMEA strings. You can also configure the sample to run in NMEA-only output mode, where only the NMEA strings are displayed in the console. In the NMEA-only output mode, you can visualize the data from the GNSS using a third-party tool.


When support for A-GNSS or P-GPS, or both, is enabled, a Zephyr workqueue is used for downloading the assistance data. Downloading the data can take some time. The workqueue ensures that the main thread is not blocked during the operation.

When assistance support is enabled, the sample receives an A-GNSS data request notification from the GNSS module, and it starts downloading the assistance data requested by the GNSS module. The sample then displays the information in the terminal about the download process. Finally, after the download completes, the sample switches back to the previous display mode.


To download assistance data, your device must have a valid JWT signing key installed and registered with nRF Cloud.

(See nRF Cloud REST API and Securely generating credentials for more details on this requirement).

If you are using nRF9160 DK, modem version v1.3.x or later is required. Your nRF9160 DK may ship with modem firmware older than v1.3.x, so verify that you have the latest installed. For an nRF9161 DK, modem version v2.0.0 or later is required.

For instructions on updating your device’s modem firmware, see the following documents:

To obtain and register a valid signing key, you can do one of the following:

  • Provision your device on nRF Cloud using Just-In-Time Provisioning (JITP) (detailed below).

  • Provision your device on nRF Cloud with preconnect provisioning (detailed in nRF Cloud Provisioning).

  • Install or generate a private key on your device and register its public key with nRF Cloud (detailed in Securely generating credentials).

To provision your device on nRF Cloud using JITP, complete the following steps:

  1. Ensure valid nRF Cloud credentials are installed. nRF91 Series DK and Thingy:91 have credentials pre-installed, but some may be shipped with RSA256 credentials; JWT signing requires ES256 credentials. These devices need new credentials to be installed before they can perform REST requests.

  2. Install a sample or application that supports JITP. You can use the Asset Tracker V2 application for this purpose.

  3. Allow your device to connect to nRF Cloud and add it to the nRF Cloud portal. When successfully provisioned, the device appears in the devices list of the nRF Cloud portal.

  4. Once your device is provisioned, you may reinstall this sample and the provisioning persists.

Minimal assistance

GNSS satellite acquisition can also be assisted by providing factory almanac, GPS time, and coarse location to the GNSS module. Using this information, GNSS can calculate which satellites it should search for and what are the expected Doppler frequencies.

The sample includes a factory almanac that is written to the file system when the sample starts. The date for the factory almanac generation is in the factory_almanac.h file. The almanac gets inaccurate with time and should be updated occasionally. GNSS can use an almanac until it is two years old, but generally it should be updated every few months.


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

Configuration options

Check and configure the following Kconfig options for the sample:

CONFIG_GNSS_SAMPLE_NMEA_ONLY - To enable NMEA-only output mode

The NMEA-only output mode can be used for example with 3rd party tools to visualize the GNSS output.


This configuration option enables A-GNSS usage.


This configuration option enables assistance with factory almanac, time and location.

CONFIG_GNSS_SAMPLE_MODE_PERIODIC - To enable periodic fixes

This configuration option enables periodic fixes instead of continuous tracking.

CONFIG_GNSS_SAMPLE_PERIODIC_INTERVAL - To set interval (in seconds) for periodic fixes

This configuration option sets the desired fix interval.

CONFIG_GNSS_SAMPLE_PERIODIC_TIMEOUT - To set desired timeout (in seconds) for periodic fixes

This configuration option sets the desired timeout for periodic fixes.

CONFIG_GNSS_SAMPLE_MODE_TTFF_TEST - To enable time-to-first-fix (TTFF) test mode

This configuration enables the TTFF test mode instead of continuous tracking. When TTFF test mode is enabled, the CONFIG_GNSS_SAMPLE_NMEA_ONLY option is automatically selected.

CONFIG_GNSS_SAMPLE_MODE_TTFF_TEST_INTERVAL - To set the time between fixes in TTFF test mode

This configuration option sets the time between fixes in TTFF test mode.

CONFIG_GNSS_SAMPLE_MODE_TTFF_TEST_COLD_START - To perform cold starts in TTFF test mode

This configuration option makes the sample perform GNSS cold starts instead of hot starts in TTFF test mode. When assistance is used, LTE may block the GNSS operation and increase the time needed to get a fix.

CONFIG_GNSS_SAMPLE_LTE_ON_DEMAND - To disable LTE after assistance download

When using assistance, LTE may block the GNSS operation and increase the time needed to get a fix. This configuration option disables LTE after the assistance data has been downloaded, so that GNSS can run without interruptions.

Additional configuration

Check and configure the following library option that is used by the sample:

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/gnss 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.

If the sample is to be used with the SUPL client library, the library must be downloaded and enabled in the sample configuration. You can download it from the Nordic Semiconductor website. See SUPL client and SUPL client OS integration for information on installing and enabling the SUPL client library.


After programming the sample and all the prerequisites to the development kit, test it by performing the following steps:

  1. Connect your nRF91 Series DK to the PC using a USB cable and power on or reset your nRF91 Series DK.

  2. Open a terminal emulator.

  3. Test the sample by performing the following steps:

    If the default output mode is enabled:

    1. Observe that the following information is displayed in the terminal emulator:

      Tracking:  0 Using:  0 Unhealthy: 0
      Seconds since last fix: 1
      Searching [-]
      NMEA strings:
    2. Observe that the numbers associated with the displayed parameters Tracking and Using change.

    3. Observe that the sample displays the following information upon acquiring a fix:

      Tracking:  7 Using:  5 Unhealthy: 0
      Latitude:       61.491275
      Longitude:      23.771611
      Altitude:       116.3 m
      Accuracy:       4.2 m
      Speed:          0.0 m/s
      Speed accuracy: 0.8 m/s
      Heading:        0.0 deg
      Date:           2020-03-06
      Time (UTC):     05:48:24
      PDOP:           3.1
      HDOP:           2.1
      VDOP:           2.3
      TDOP:           1.8
      NMEA strings:

    If NMEA-only output mode is enabled:

    1. Observe that the following information is displayed in the terminal emulator:


    If TTFF test mode is enabled:

    1. Observe that the following information is displayed in the terminal emulator:

      [00:00:34.790,649] <inf> gnss_sample: Time to fix: 34
      [00:00:34.796,447] <inf> gnss_sample: Sleeping for 120 seconds
      [00:02:34.699,493] <inf> gnss_sample: Starting GNSS
      [00:02:35.940,582] <inf> gnss_sample: Time to fix: 1
      [00:02:35.946,319] <inf> gnss_sample: Sleeping for 120 seconds
    2. Observe that the samples displays the time to fix for each fix.

    If A-GNSS and/or P-GPS support is enabled:

    1. Observe that the following message is displayed in the terminal emulator immediately after the device boots:

      [00:00:04.488,494] <inf> gnss_sample: Assistance data needed, ephe 0xffffffff, alm 0xffffffff, flags 0x3b
    2. Observe the following actions in the terminal emulator:

      1. The sample downloads the requested assistance data if needed (with P-GPS, the data may already be available in the flash memory).

      2. The sample continues after the download has completed.


This sample uses the following nRF Connect SDK libraries:

It uses the following sdk-nrfxlib library:

It uses the following Zephyr library:

In addition, it uses the following secure firmware component: