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.
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)
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.
- Compile and program the application. The device should now be advertising.
- Prepare the Linux router device by initializing the 6LoWPAN module.
- Check that you have set up the TFTP server - see Setup of a TFTP server on Linux for more information.
- Discover the advertising device using the hcitool lescan command.
- Connect to the discovered device from the Linux console using the Bluetooth 6LoWPAN connect command.
- Check if the connected state is reflected by the LEDs (LED 2 is ON).
- Ensure that the kit has an IPv6 Internet connection.
- 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).
- Press Button 1 on the board to read file.
- Observe the serial console. After a few seconds it should display the file contents at the end of the transfer.
- Press Button 2 on the kit to write the file.
- Observe the serial console. After a few seconds it should display the file contents of the written file at the end of the transfer.
- Press Button 1 on the board to check if the read file has modified content.
- Observe the serial console. After a few seconds it should display the modified file contents at the end of the transfer.
- Disconnect from the device by using the Bluetooth 6LoWPAN disconnect command.
- 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:
- Connect a USB cable from your computer to the nRF52 board.
- Check the list of available serial (COM) ports. The new interface should appear after connecting the board.
- 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 |