UDP

The UDP sample demonstrates how to perform sequential transmissions of UDP packets to a server using an IP-connected device. The sample connects to an LTE network using an nRF91 Series DK or Thingy:91, or to Wi-Fi using the nRF7002 DK.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Build target

Thingy:91

PCA20035

thingy91_nrf9160

thingy91_nrf9160_ns

nRF9161 DK

nrf9161dk_nrf9161

nrf9161dk_nrf9161_ns

nRF9160 DK

PCA10090

nrf9160dk_nrf9160

nrf9160dk_nrf9160_ns

nRF7002 DK

PCA10143

nrf7002dk_nrf5340

nrf7002dk_nrf5340_cpuapp

Additionally, the sample supports emulation using QEMU x86.

Overview

The sample connects through either an LTE network or Wi-Fi, depending on the selected target board. Once connected, it sets up a UDP socket and continuously transmits data over the socket to a configurable IP address and port number.

Configuration

See Configuring your application for information about how to permanently or temporarily change the configuration.

Configuration options

Check and configure the following configuration options:

CONFIG_UDP_SAMPLE_DATA_UPLOAD_SIZE_BYTES - UDP data upload size

This configuration option sets the number of bytes that are transmitted to the server.

CONFIG_UDP_SAMPLE_DATA_UPLOAD_FREQUENCY_SECONDS - UDP data upload frequency

This configuration option sets how often the sample transmits data to the server.

CONFIG_UDP_SAMPLE_SERVER_ADDRESS_STATIC - UDP Server IP Address

This configuration option sets the static IP address of the server.

CONFIG_UDP_SAMPLE_SERVER_PORT - UDP server port configuration

This configuration option sets the server address port number.

Configuration files

The sample provides predefined configuration files for the following development kits:

  • prj.conf - General configuration file for all devices.

  • boards/nrf9160dk_nrf9160_ns.conf - Configuration file for the nRF9160 DK.

  • boards/nrf9161dk_nrf9161_ns.conf - Configuration file for the nRF9161 DK.

  • boards/thingy91_nrf9160_ns.conf - Configuration file for the Thingy:91.

  • boards/nrf7002dk_nrf5340_cpuapp.conf - Configuration file for the nRF7002 DK.

  • boards/qemu_x86.conf - Configuration file for QEMU x86 emulation.

Building and running

This sample can be found under samples/net/udp 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 Building and programming an application for other building and programming scenarios and Testing and debugging an application for general information about testing and debugging in the nRF Connect SDK.

Testing

After programming the sample to your device, test it by performing the following steps:

  1. Connect the kit to the computer using a USB cable. The kit is assigned a COM port (Windows) or ttyACM device (Linux), which is visible in the Device Manager.

  2. Connect to the kit with a terminal emulator (for example, PuTTY). See How to connect with PuTTY for the required settings.

  3. Observe that the sample shows output similar to the following in the terminal emulator:

    *** Booting nRF Connect SDK v2.4.99-dev2-114-g305275323644 ***
    [00:00:00.268,920] <inf> udp_sample: UDP sample has started
    [00:00:00.268,951] <inf> udp_sample: Bringing network interface up and connecting to the network
    [00:00:05.557,800] <inf> udp_sample: Network connectivity established
    [00:00:05.558,715] <inf> udp_sample: Transmitting UDP/IP payload of 38 bytes to the IP address 8.8.8.8, port number 2469
    

Troubleshooting

If you have issues with connectivity on nRF91 Series devices, see the Cellular Monitor documentation to learn how to capture modem traces in order to debug network traffic in Wireshark. This sample enables modem traces by default.

Dependencies

This sample uses the following nRF Connect SDK and Zephyr libraries: