nRF5 IoT SDK
v0.9.0
|
This nRF UDP Client example shows the usage of Nordic's IPv6 Stack for sending and receiving UDP packets. The server is identified by its IPv6 address, which needs to be configured in main.c
. The client application sends ICMPv6 echo requests to the server to determine whether it is reachable or not. Once an echo response is received, the application starts to send UDP packets to the peer. The port numbers for transmitting and receiving UDP packets are also configured in main.c
. The payload of the UDP packets is 20 bytes in length and has the following format:
Packet sequence number in uint32 format (4 bytes) | 16 bytes of random data |
Each transmitted packet is stored until it is received back or until the buffer is full. The buffer of transmitted packets is of PACKET_BUFFER_LEN in length. When it becomes full, the transmission of UDP packets stops and the buffer is emptied. The packet sequence number is set to zero. Echo requests are sent to the server to determine if it is reachable. When an echo response is received, the transmission of UDP packets starts again. The operation of the application is reflected by two LEDs on the board.
The UDP server could be a PC application communicating to the UDP client on the kit, as shown in Figure 1 below.
Or, the UDP server could be the example server application included in the SDK responding to requests from this example application in Figure 2.
Figure 3 shows the application state diagram.
Configuration parameters for all used modules are defined and described in the sdk_config.h file. This file is located in the config subfodler of the main application folder. For the server address and UDP port configuration, see main.c
.
This section summarizes the usage of nRF5x resources and common modules in the examples apart from the IoT 6lowpan and IPv6 stack library.
Module | Inclusion/Usage | Description |
---|---|---|
Timer | 2 | Two timers are used - one timer for LED blinks and one for time-out on the echo response. |
Buttons | 0 | No buttons are used in this examples. |
LEDs | 4 | LEDs are used to indicate the application states. See LED assignments section for details. |
Adv Data Encoder | Yes | The device name used is 'UDP6_Client_Node', IPSP Service UUID is included in the UUID list. |
Scheduler | No | Scheduler is used for processing stack events. |
UART Trace | Included not enabled | Tracing is included but not enabled by default. |
You can find the source code and project files of the example in the following folder:
<InstallFolder>/examples/iot/udp/ipv6/client
LED assignments:
LED 1 | LED 2 | |
---|---|---|
Blinking | Off | Device advertising as BLE peripheral. |
On | Off | BLE link established, IPv6 interface down. |
On | Blinking | IPv6 interface up, echo requests are sent to the server. |
Blinking | On | UDP packets are sent to the server. |
On | On | Assertion failure in the application. |
See Connecting devices to the router for a list of relevant Linux commands.
Use the code below to start a simple Python server that listens on port 9000, prints the sequence number from incoming packets and transmits them back to the sender.
sysctl -w net.ipv6.conf.all.forwarding=1
.