Cellular: UDP
The Cellular: 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 control library.
Requirements
The sample supports the following development kits:
Hardware platforms |
PCA |
Board name |
Board target |
---|---|---|---|
PCA20065 |
thingy91x |
|
|
PCA20035 |
thingy91 |
|
|
PCA10153 |
|
||
PCA10090 |
|
||
PCA10171 |
|
When built for a board target with the */ns
variant, 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.
Overview
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 control 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 prj.conf
.
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.
You can use this sample to characterize the current consumption of the nRF91 Series SiP. This is due to the simple UDP/IP behavior demonstrated by the sample, which makes it suitable for current measurement.
Note
Logging output is disabled by default in this sample to produce the lowest possible amount of current consumption.
Measuring current
Refer to the following documents for measuring currents:
nRF9151 DK- Measuring Current on nRF9151 DK
nRF9161 DK- Measuring Current on nRF9161 DK
nRF9160 DK- Measuring Current on nRF9160 DK
Thingy:91- Measuring Current on Thingy:91
Configuration
See Configuring and building for information about how to permanently or temporarily change the configuration.
Configuration options
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_DATA_UPLOAD_ITERATIONS - UDP data upload iterations configuration
This configuration option sets the number of times the sample transmits data to the server before shutting down. Set to
-1
to transmit indefinitely.
- CONFIG_UDP_SERVER_ADDRESS_STATIC - UDP Server IP Address configuration
This configuration option sets the 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 and cellular network.
- CONFIG_UDP_EDRX_ENABLE - eDRX mode configuration
This configuration option, if set, allows the sample to request eDRX from the modem and cellular network.
- CONFIG_UDP_RAI_ENABLE - RAI configuration
This configuration option, if set, allows the sample to request RAI for transmitted messages.
- CONFIG_UDP_RAI_NO_DATA - RAI indication configuration
This configuration option, if set, allows the sample to indicate that there will be no upcoming data transmission anymore after the previous transmission.
- CONFIG_UDP_RAI_LAST - RAI indication configuration
This configuration option, if set, allows the sample to indicate that the next transmission will be the last one for some duration.
- CONFIG_UDP_RAI_ONGOING - RAI indication configuration
This configuration option, if set, allows the sample to indicate that the client expects to use more socket after the next transmission.
Note
To configure PSM and eDRX timer values, use the options from the LTE link control library.
Additional configuration
The following configurations are recommended for low power behavior:
CONFIG_SERIAL
disabled.CONFIG_LTE_PSM_REQ_RPTAU
option set to a value greater than the value of CONFIG_UDP_DATA_UPLOAD_FREQUENCY_SECONDS.CONFIG_LTE_PSM_REQ_RAT
set to 0.CONFIG_UDP_PSM_ENABLE enabled.
CONFIG_UDP_EDRX_ENABLE disabled.
CONFIG_UDP_RAI_ENABLE enabled.
Note
In applications where downlink messaging from the cloud to the device is expected, we recommend setting
the CONFIG_LTE_PSM_REQ_RAT
option to a higher value than 0
to ensure data is received
before the device enters PSM.
PSM and eDRX timers are set with binary strings that signify a time duration in seconds. For a conversion chart of these timer values, see the Power saving mode setting section in the nRF9160 AT Commands Reference Guide or the same section in the nRF91x1 AT Commands Reference Guide, depending on the SiP you are using.
Note
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.
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/udp
in the nRF Connect SDK folder structure.
When built as firmware image for a board target with the */ns
variant, 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, 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 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, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.
Enable logging by setting the
CONFIG_SERIAL
option toy
in theprj.conf
configuration file.Observe that the sample shows output similar to the following in the terminal emulator:
*** Booting nRF Connect SDK v2.5.0-241-g5ada4583172b *** UDP sample has started LTE cell changed: Cell ID: 37372427, Tracking area: 4020 RRC mode: Connected Network registration status: Connected - roaming PSM parameter update: TAU: 3600 s, Active time: 0 s Transmitting UDP/IP payload of 38 bytes to the IP address 8.8.8.8, port number 2469 RRC mode: Idle Transmitting UDP/IP payload of 38 bytes to the IP address 8.8.8.8, port number 2469 RRC mode: Connected RRC mode: Idle Transmitting UDP/IP payload of 38 bytes to the IP address 8.8.8.8, port number 2469 RRC mode: Connected RRC mode: Idle
Testing RAI feature
Test the RAI feature 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, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.
Connect the nRF91 Series DK to the Power Profiler Kit II (PPK2) and set up for current measurement.
Install the Power Profiler app in the nRF Connect for Desktop.
Connect the Power Profiler Kit II (PPK2) to the PC using a micro-USB cable and connect to it using the App.
Enable RAI by setting the CONFIG_UDP_RAI_ENABLE option to
y
in theprj.conf
configuration file.Update the data upload frequency by setting the CONFIG_UDP_DATA_UPLOAD_FREQUENCY_SECONDS option to
30
in theprj.conf
configuration file.Program the sample to the device.
Power on or reset your nRF91 Series DK.
In the Power Profiler app choose a one minute time window.
Observe that after some minutes the average power consumption will settle at around 1.7 mA (may vary depending on network conditions).
Disable RAI by setting the CONFIG_UDP_RAI_ENABLE option to
n
in theprj.conf
configuration file.Program the sample to the device.
Power on or reset your nRF91 Series DK.
Observe that after some minutes the average power consumption will settle at around 2.3 mA (may vary depending on network conditions).
Observe that power consumption with RAI enabled is lower than with RAI disabled.
Dependencies
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: