NetBurner 3.5.6
PDF Version
TFTP Client

TFTP Client Application

Overview

This NetBurner TFTP Client example demonstrates how to use a NetBurner device to communicate with a TFTP (Trivial File Transfer Protocol) server for both file upload and download operations.

Features

  • File Download: Retrieve files from a TFTP server using the GetTFTP() function
  • File Upload: Send files to a TFTP server using the SendTFTP() function
  • Configurable Server: Support for specifying TFTP server IP address
  • Error Handling: Comprehensive error checking and timeout management
  • Binary and Text Modes: Support for both binary ("b") and text ("t") transfer modes

Requirements

TFTP Server Configuration

  1. The TFTP server must be configured to handle both read and write operations
  2. Ensure the server allows file transfers in the directory where test files will be stored

NetBurner Device Configuration

The TFTP server address can be configured through multiple methods:

  • NetBurner device's Configuration Server web interface
  • Direct modification in the application code (currently set to 10.1.1.100)
  • Serial Configuration Server of the device
  • Application data flash memory using configuration parameters

Application Flow

Initialization

  1. Initialize the network stack
  2. Enable system diagnostics
  3. Start HTTP web server on default port 80
  4. Wait for DHCP address assignment (5-second timeout)

TFTP Operations

  1. File Upload Test: Creates a sample text file with 10 lines and uploads it as "tftp.txt"
  2. File Download Test: Downloads "tftp.txt" from the TFTP server
  3. Results Display: Shows operation results and data content

Code Structure

Key Functions

SendTFTP_Test()

  • Creates sample data (10 lines of text)
  • Uploads data to TFTP server as "tftp.txt"
  • Handles upload results and error conditions

ReadTFTP_Test()

  • Downloads "tftp.txt" from TFTP server
  • Displays received data and byte count
  • Handles download results and error conditions

UserMain()

  • Main application entry point
  • Performs initialization sequence
  • Executes both send and receive tests
  • Enters infinite loop after completion

Configuration Parameters

#define TFTP_SERVER_IP "10.1.1.100" // Default TFTP server IP address
const int bufferSize = 1024; // Transfer buffer size

TFTP Function Parameters

Both GetTFTP() and SendTFTP() functions use similar parameter structures:

  • Filename: Name of file to transfer ("tftp.txt")
  • Mode: Transfer mode - "b" for binary, "t" for text
  • Buffer: Data buffer for transfer operations
  • Length: Data length for transfers
  • Timeouts: Operation and packet-level timeout values
  • Server IP: TFTP server IP address

Return Codes

The application handles three main TFTP return codes:

  • TFTP_OK: Operation completed successfully
  • TFTP_TIMEOUT: Operation timed out
  • TFTP_ERROR: Error occurred during operation

Usage Instructions

  1. Setup TFTP Server: Configure a TFTP server on your network with read/write permissions
  2. Configure IP Address: Update TFTP_SERVER_IP to match your TFTP server's IP address
  3. Build and Deploy: Compile and deploy the application to your NetBurner device
  4. Network Connection: Ensure the NetBurner device is connected to the same network as the TFTP server
  5. Monitor Output: Use a serial terminal to view application output and results
  6. Reset to Repeat: Reset the device to run the test sequence again

Test Files

The application works with a test file named "tftp.txt":

  • Upload Test: Creates and sends a file with 10 numbered lines
  • Download Test: Retrieves the same file from the server
  • Content Verification: Displays received data for verification

Network Requirements

  • DHCP-enabled network for automatic IP assignment
  • Network connectivity between NetBurner device and TFTP server
  • TFTP server listening on standard port 69
  • Firewall permissions for TFTP traffic

Troubleshooting

Common Issues

  • Timeout Errors: Check network connectivity and TFTP server status
  • Permission Errors: Verify TFTP server write permissions
  • File Not Found: Ensure test file exists on server for download operations
  • Network Issues: Confirm DHCP assignment and IP connectivity

Debug Information

  • System diagnostics are enabled by default
  • Serial output provides detailed operation status
  • HTTP server runs on port 80 for additional configuration options

Customization Options

Server Configuration

Replace hardcoded IP with configurable parameters:

static config_string gTftpServerName{appdata, "DNS_or_IPAddress", "TFTP_SERVER"};
// or
static config_IPADDR4 gTftpServerAddress(appdata, "10.1.1.123", "TFTP_SERVER");
Configuration Variable for IPADDR4 (IPv4) object types.
Definition config_obj.h:1493
String Configuration Variable.
Definition config_obj.h:1127

Buffer Size

Adjust bufferSize constant to handle larger file transfers as needed.

Timeout Values

Modify timeout parameters in function calls:

  • TICKS_PER_SECOND * 10: Overall operation timeout
  • TICKS_PER_SECOND * 5: Individual packet timeout

Development Notes

  • Remove EnableSystemDiagnostics() for production deployments
  • Consider implementing error recovery mechanisms for production use
  • The application demonstrates basic TFTP functionality suitable for embedded systems
  • HTTP server provides additional configuration capabilities through web interface