nRF9160: GPS sockets and SUPL client library

The GPS sample demonstrates how to retrieve GPS data. If Secure User-Plane Location (SUPL) support is enabled, it also shows how to improve the GPS fix accuracy and fix speed with A-GPS data from a SUPL server. See SUPL client for information on enabling SUPL support for the sample.

The sample first creates a GNSS socket. See BSD library and BSD socket extensions for more information about GNSS sockets. Then it reads the GPS data from the socket and parses the received frames to interpret the frame contents.


This sample operates in three different modes. Each of these modes depends on the state of the GPS module.

Mode 1

This is the startup mode in which the sample waits for the GPS module to acquire a fix on the current position. Information about the progress is displayed on a console.

Mode 2

The sample switches to the second mode when the GPS module has acquired at least one fix. In this mode, the sample also displays information about the last good fix received from the GPS module. The displayed information includes both PVT (Position, Velocity, and Time) and NMEA strings.

Mode 3

The sample operates in this mode only if SUPL client support is enabled. When the sample receives an A-GPS notification from the GPS module, the sample switches from the current mode to the third mode and starts downloading the A-GPS data requested by the GPS module. The sample then displays the information on the screen about the download process. Finally, the sample switches back to the previous mode when the download is completed.


  • The following development board:

  • Optional: SUPL Client library (for details on download, see SUPL client)

Building and running

This sample can be found under samples/nrf9160/gps in the nRF Connect SDK folder structure.

The sample is built as a non-secure firmware image for the nrf9160_pca10090ns board. Because of this, it automatically includes the nRF9160: Secure Partition Manager.

See Building and programming a sample application for information about how to build and program the application.

Using the sample with the SUPL client library

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 for information on installing and enabling the SUPL client library.

The SUPL client library is not required, and the sample will work without A-GPS support if the library is not available.


After programming the sample and all the prerequisites to the board, you can test the sample by performing the following steps:

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

  2. Open a terminal emulator.

  3. Test the sample by performing the following steps:

    If SUPL client library support is not enabled:

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

      Tracking: 0 Using: 0 Unhealthy: 0
      Seconds since last fix 0
      Scanning [/]
    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 the first GPS lock:

      Tracking: 7 Using: 7 Unhealthy: 0
      Seconds since last fix 0
      Longitude:  10.437814
      Latitude:   63.421546
      Altitude:   163.747833
      Speed:      0.023171
      Heading:    0.000000
      Date:       30-01-2020
      Time (UTC): 09:42:38
      NMEA strings:

    If SUPL client library support is enabled:

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

      New AGPS data requested, contacting SUPL server, flags 59.
    2. Observe the following actions in the terminal emulator:

      1. The sample switches to LTE and connects to a SUPL server.

      2. The A-GPS data gets downloaded.

      3. The sample continues after the SUPL session is complete.


This sample uses the following libraries:

From nRF Connect SDK
From nrfxlib
From Zephyr