The UDP sample demonstrates the sequential transmission of UDP packets to a predetermined server identified by an IP address and a port. The sample uses the Modem library and LTE link controller library.
The sample supports the following development kits:
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.
Additionally, it supports X86 Emulation (QEMU).
The sample acts directly on socket level abstraction.
It configures a UDP socket and continuously transmits data over the socket to the modem’s TCP/IP stack, where the data eventually gets transmitted to a server specified by an IP address and a port number.
To control the LTE link, it uses the LTE link controller library and requests Power Saving Mode (PSM), extended Discontinuous Reception (eDRX) mode and Release Assistance Indication (RAI) parameters.
These parameters can be set through the sample configuration file
You can configure the frequency with which the packets are transmitted and the size of the UDP payload through the Kconfig system. In addition to setting of the above options, you can also set the various LTE parameters that are related to current consumption for adding low power behavior to the device.
The UDP sample can be used to characterize the current consumption of the nRF9160 SiP. This is due to the simple UDP/IP behavior demonstrated by the sample, which makes it suitable for current measurement.
Logging output is disabled by default in this sample to produce the lowest possible amount of current consumption.
For measuring current on an nRF9160 DK, it must first be prepared as described in Measuring Current on nRF9160 DK. If you are measuring current on a Thingy:91, see Measuring Current on Thingy:91.
See Configuring your application for information about how to permanently or temporarily change the configuration.
Check and configure the following configuration options for the sample:
- CONFIG_UDP_DATA_UPLOAD_SIZE_BYTES - UDP data upload size configuration
This configuration option sets the number of bytes to be transmitted to the server.
- CONFIG_UDP_DATA_UPLOAD_FREQUENCY_SECONDS - UDP data upload frequency configuration
This configuration option sets the frequency with which the sample transmits data to the server.
- CONFIG_UDP_SERVER_ADDRESS_STATIC - UDP Server IP Address configuration
This configuration option sets the static IP address of the server.
- CONFIG_UDP_SERVER_PORT - UDP server port configuration
This configuration option sets the server address port number.
- CONFIG_UDP_PSM_ENABLE - PSM mode configuration
This configuration option, if set, allows the sample to request PSM from the modem or cellular network.
- CONFIG_UDP_EDRX_ENABLE - eDRX mode configuration
This configuration option, if set, allows the sample to request eDRX from the modem or cellular network.
- CONFIG_UDP_RAI_ENABLE - RAI configuration
This configuration option, if set, allows the sample to request RAI for transmitted messages.
PSM, eDRX and RAI value or timers are set using the configurable options for the LTE link controller library.
The following configurations are recommended for low power behavior:
CONFIG_LTE_PSM_REQ_RPTAUoption set to a value greater than the value of CONFIG_UDP_DATA_UPLOAD_FREQUENCY_SECONDS.
CONFIG_LTE_PSM_REQ_RATset to 0.
CONFIG_UDP_EDRX_ENABLE set to false.
CONFIG_UDP_RAI_ENABLE set to true for NB-IoT. It is not supported for LTE-M.
PSM and eDRX timers are set with binary strings that signify a time duration in seconds. See Power saving mode setting section in AT commands reference document for a conversion chart of these timer values.
The availability of power saving features or timers is entirely dependent on the cellular network. The above recommendations may not be the most current efficient if the network does not support the respective feature.
The sample provides predefined configuration files for the following development kits:
prj.conf- For nRF9160 DK and Thingy:91
prj_qemu_x86.conf- For x86 Emulation (QEMU)
They are located in
Building and running
This sample can be found under
samples/nrf9160/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.
After programming the sample to your device, test it by performing the following steps:
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.
Connect to the kit with a terminal emulator (for example, PuTTY). See How to connect with PuTTY for the required settings.
Enable logging by setting the
Observe that the sample shows output similar to the following in the terminal emulator:
*** Booting Zephyr OS build v2.3.0-rc1-ncs1-1451-gb160c8c5caa5 *** UDP sample has started LTE cell changed: Cell ID: 33703711, Tracking area: 2305 PSM parameter update: TAU: 110287, Active time: 61024 RRC mode: Connected Network registration status: Connected - roaming PSM parameter update: TAU: -1, Active time: -1 Transmitting UDP/IP payload of 38 bytes to the IP address 18.104.22.168, port number 2469 PSM parameter update: TAU: 3600, Active time: 0 RRC mode: Idle Transmitting UDP/IP payload of 38 bytes to the IP address 22.214.171.124, port number 2469 RRC mode: Connected RRC mode: Idle Transmitting UDP/IP payload of 38 bytes to the IP address 126.96.36.199, port number 2469 RRC mode: Connected RRC mode: Idle
This sample uses the following nRF Connect SDK library:
It uses the following sdk-nrfxlib library:
In addition, it uses the following secure firmware component: