nRF5 IoT SDK  v0.9.0
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
TFTP client

The Trivial File Transfer Protocol (TFTP) is a UDP based transfer protocol for transferring files between hosts. To demonstrate TFTP protocol support on nRF52, Nordic's IPv6 stack is used. This application implements a simple TFTP client to get a single file (test.txt), modify it, and push it back to the server.

The example requires the test.txt file to be writable. Use the following command to enable this.

sudo chmod 757 /srv/tftp/test.txt
Note
A demo requires an IPv6 TFTP server to download and upload files. To see how to install a simple TFTP server on Linux see Setup of a TFTP server on Linux.

The demo setup and flow diagram are presented in Figure 1.


tftp_link_local.svg
Figure 1: Setup of the TFTP client application


Overview

This example demonstrates how Nordic's IPv6 stack can be used for getting and receiving files from a TFTP server.

The application is controlled by buttons. By pressing BUTTON 1 you can download the test.txt file from the TFTP server, which fills the internal static buffer. After pressing BUTTON 2 the application will add a "Hello!" string at the end of the file and overwrite its content on the server.

Data Exchange MSC

The MSC below provides an overview of the data exchange in the application between the node (nRF52) and the router/cloud in two cases:

  • correct behavior
  • the TFTP server is unreachable (TFTP Query is sent again)

msc_nrf_tftp
Figure 2: Data exchange

Common module dependency and usage

This section summarizes the usage of nRF52 resources and common modules in the examples apart from the IoT 6LoWPAN and IPv6 stack library.

Module Inclusion/Usage Description
Timer 2 Two timers - IoT timer, button module and for timing TFTP retransmission mechanism.
Buttons 2 Buttons are used for performing TFTP transfers.
LEDs 4 LEDs are used to indicate the application states. See LED assignments.
Scheduler No The scheduler is used for processing stack events.
UART Trace Yes Tracing is used to show the file contents. Trace logs from the TFTP module are not enabled by default.
Note
To see how to read data from the UART interface see Using the UART interface.

Setup

The source code and project file of the example can be found at: <InstallFolder>/examples/iot/tftp/client

LED assignments

Application State LED 1 State LED 2 State LED 3 State LED 4 State
Idle OFF OFF OFF OFF
Advertising BLINKING OFF OFF OFF
IPv6 Interface Up OFF ON OFF OFF
IPv6 Interface Down ON BLINKING OFF OFF
ASSERT ON ON ON ON

Button assignments

TFTP operation Button number
Read file from the server 1
Append data and write file to the server 2
Note
If commissioning is enabled, additional LED and Button assignments are made.
If the application asserts, it is halted.
This application is not power optimized!

Testing

See Connecting devices to the router for a list of relevant Linux commands.

  1. Compile and program the application. The device should now be advertising.
  2. Prepare the Linux router device by initializing the 6LoWPAN module.
  3. Check that you have set up the TFTP server - see Setup of a TFTP server on Linux for more information.
  4. Discover the advertising device using the hcitool lescan command.
  5. Connect to the discovered device from the Linux console using the Bluetooth 6LoWPAN connect command.
  6. Check if the connected state is reflected by the LEDs (LED 2 is ON).
  7. Ensure that the kit has an IPv6 Internet connection.
  8. Create test.txt in the TFTP server root directory (usually /srv/tftp folder). Remember to set the owner of the file to tftp. sudo chown tftp:tftp test.txt (inside /srv/tftp). Also make sure that file has proper permission to write to it (sudo chmod 646 test.txt).
  1. Press Button 1 on the board to read file.
  2. Observe the serial console. After a few seconds it should display the file contents at the end of the transfer.
  3. Press Button 2 on the kit to write the file.
  4. Observe the serial console. After a few seconds it should display the file contents of the written file at the end of the transfer.
  5. Press Button 1 on the board to check if the read file has modified content.
  6. Observe the serial console. After a few seconds it should display the modified file contents at the end of the transfer.
  7. Disconnect from the device by using the Bluetooth 6LoWPAN disconnect command.
  8. Observe that only LED 1, which is advertising, is blinking.

Using the UART interface

By default the UART interface is connected with a J-Link virtual USB serial interface to your computer. In order to read from this interface:

  1. Connect a USB cable from your computer to the nRF52 board.
  2. Check the list of available serial (COM) ports. The new interface should appear after connecting the board.
  3. Use any program that can read from the serial interface and point it to the read port.

Default UART configuration

Property Value
Baudrate 1 000 000
Flow control XON/XOFF
Data bits 8 bits
Number of stop bits 1 bit
Parity None