In network-related product development and debugging, useful gadgets can often achieve more. Based on the network development scenario, RT-Thread developed the RT-Thread NetUtils component that collecting lots of easy-to-use network development tools for developers. The RT-Thread NetUtils component is created based on the commonly used network tools, which are dynamically configured via RT-Thread Env, it is out-of-box and can effectively reduce resource consumption. NetUtils Component Introduction RT-Thread NetUtils serves as a network tool gadget, it is useful in ping commands for testing debugging; NTP tools for time sync; Iperf, NetIO for performance and bandwidth testing; and lightweight file transfer tool TFTP that widely used in embedded systems, to easily transfer files between two devices over the network. In addition, RT-Thread provides advanced aids to solve the practical problem, such as Telnet tools that can log on remotely to RT-Thread Finsh/MSH Shell, and tcpdump packet capture tool that based lwIP. Here are the categories of RT-Thread NetUtils: Each gadget can be enabled/disabled independently using menuconfig and provides Finsh/MSH commands. Start by opening the RT-Thread Env tool, entering the BSP directory, entering menuconfig on the Env command line for entering the configuration interface to configure project, and selecting the right NetUtils functionality for your needs, as shown below: Notes: Pings and TFTPs rely on lwIP and need to turn on lwIP dependencies before they can be displayed. RT-Thread online packages -> IoT - internet things -> netutils: Networking utilities RT-Thread of for Ping Ping is a network diagnostic tool that tests whether packets can reach a particular host through an IP protocol. Estimating packet loss rates (drop rates) and packet round-trip times with hosts (network latency, Round-trip delay time) The Ping tool relies on lwIP and needs to enable the lwIP dependency in the Env tool before it can be seen, as shown as follows: -> RT-Thread Components -> Network stack -> light weight TCP/IP stack -> Enable lwIP stack Enable ping options in the NetUtils menu bar: RT-Thread online packages -> IoT - internet things -> netutils: Networking utilities RT-Thread [*] Enable Ping utility of for Ping supports access to 'IP address' or 'domain name' and is tested using the Finsh/MSH command, as follows: Ping domain name. msh />ping rt-thread.org bytes icmp_seq= ttl= time= ticks bytes icmp_seq= ttl= time= ticks bytes icmp_seq= ttl= time= ticks bytes icmp_seq= ttl= time= ticks msh /> 60 from 116.62 .244 .242 0 49 11 60 from 116.62 .244 .242 1 49 10 60 from 116.62 .244 .242 2 49 12 60 from 116.62 .244 .242 3 49 10 Ping IP msh />ping bytes icmp_seq= ttl= time= ticks bytes icmp_seq= ttl= time= ticks bytes icmp_seq= ttl= time= ticks bytes icmp_seq= ttl= time= ticks msh /> 192.168 .10 .12 60 from 192.168 .10 .12 0 64 5 60 from 192.168 .10 .12 1 64 1 60 from 192.168 .10 .12 2 64 2 60 from 192.168 .10 .12 3 64 3 NTP NTP is the Network Time Protocol that used to synchronize the time of individual computers on the network. NTP clients are implemented on RT-Thread, and when connected to the network, the current UTC time can be obtained and updated to the RTC. Enable the NTP option in the NetUtils menu bar: RT-Thread online packages -> IoT - internet things -> netutils: Networking utilities RT-Thread [*] Enable NTP(Network Time Protocol) client of for Access UTC. UTC also known as world-uniform time, world standard time, and international coordination time. Beijing time is 8 hours earlier than UTC. The UTC function prototype is `time_t time_t ntp_get_time(void)`, if the return value is greater than 0, time successfully accessed, if the return value is equal to 0, time failed accessed. Example code: #include <ntp.h> main( ) { time_t cur_time; cur_time = ntp_get_time(); (cur_time) { rt_kprintf( , ctime(( time_t*) &cur_time)); } } void void if "NTP Server Time: %s" const Access Local Time Local time has time zone concept. The local time function prototype is `time_t ntp_get_local_time(void)`, and if the return value is greater than 0, time successfully accessed, if the return value is equal to 0, time failed accessed. The API is used in a similar way of `ntp_get_time()`. Sync Local Time to RTC If enable RTC device, you can also use the following commands and APIs to sync NTP local time to the RTC device. The Finsh/MSH command works as follows: msh />ntp_sync Get local time NTP server: Sat Feb : : The system time is updated. Timezone is msh /> from 10 15 22 33 2018 8. The prototype function for sync local time to RTC function is: `time_t ntp_sync_to_rtc(void)`, if the return value is greater than 0, time successfully accessed, if the return value is equal to 0, time failed accessed. Notes The NTP APIs consume a lot of stack space during invocation, so it's important to make sure there is enough free space (not less than 1.5KB) in stack. The NTP APIs are not reentrant, whose invocation must be serialized with locks. TFTP TFTP (Trivial File Transfer Protocol) is used in the TCP/IP protocol suite for trivial file transfer between clients and servers, providing a simple and low-cost file transfer service, the port number is 69, much lighter than traditional FTP protocols, and which is more suitable for small embedded products. RT-Thread currently supports TFTP servers. The TFTP tool relies on lwIP and needs to enable the lwIP dependency in the RT-Thread Env tool before it can be seen, as shown as follows: -> RT-Thread Components -> Network stack -> light weight TCP/IP stack -> Enable lwIP stack Enable the TFTP option in the NetUtils menu bar: RT-Thread online packages -> IoT - internet things -> netutils: Networking utilities RT-Thread [*] Enable TFTP(Trivial File Transfer Protocol) server of for The installation file is located in `netutils/tools/Tftpd64-4.60-setup.exe`, please install the software before using TFTP. Install the TFTP client. Before transferring files, you need to start the TFTP server using the Finsh/MSH command on RT-Thread, as follows: Start the TFTP server. msh />tftp_server TFTP server start successfully. msh /> Transfer File Open the installed `Tftpd64` and configure it as shown as follows: 1. Choose `Tftp Client`; 2. Pull down `Server interfaces` to select the same network segment of the network interface card as RT-Thread; 3. Fill in the IP address of the TFTP server. The IP address can be viewed by entering the `ifconfig` command; 4. Fill in the port number of TFTP server with `69`. Send File to RT-Thread 1. Select the file to be sent in `Tftpd64` 2. `Remote File` is the path to save files on the server side (including file names), the options support relative and absolute paths. Since RT-Thread enable the `DFS_USING_WORKDIR`option by default at this point the relative path is based on the Finsh/MSH entered directory. Therefore, when using relative paths, it is important to switch directories in advance 3. Click on the `Put` button As shown in the following image, the file is sent to the Finsh/MSH entered directory, where the relative path is used: Notes If `DFS_USING_WORKDIR` is not enabled and `Remote File` is empty, the file will be saved under the root path. Receive File From RT-Thread 1. Fill in the file path in `Tftpd64` to receive the saved file(including file name) 2. `Remote File` is the file path to be received back on the server side (including file names), the options support relative and absolute paths. Since RT-Thread enable the `DFS_USING_WORKDIR` option by default at this point the relative path is based on the Finsh/MSH entered directory. Therefore, when using relative paths, it is important to switch directories in advance 3. Click on the `Get` button Save `/web_root/image.jpg` to the local, here we are using absolute path, as shown below: msh /web_root>ls ## Check out file exsits Directory /web_root: image.jpg msh /web_root> if 10559 Iperf Iperf is a network performance testing tool. Iperf can test the maximum bandwidth performance of TCP and UDP with a variety of parameters and UDP characteristics that can be adjusted as needed, and it can report bandwidth, delay jitter, and packet loss. Enable the Iperf option in the NetUtils menu bar: RT-Thread online packages -> IoT - internet things -> netutils: Networking utilities RT-Thread [*] Enable iperf-liked network performance tool of for Iperf uses a client–server model, with servers at one end and clients at the other, and the Iperf package RT-Thread provided that implements TCP server mode and client mode, we will give an introduction about these 2 modes. Iperf Server Mode Obtain IP address. You'll need to use the Finsh/MSH command on RT-Thread to obtain an IP address, as shown as follows: msh />ifconfig network interface: e0 (Default) MTU: MAC: f e5 FLAGS: UP LINK_UP ETHARP ip address: gw address: net mask : dns server # : dns server # : 1500 00 04 9 05 44 192.168 .12 .71 192.168 .10 .1 255.255 .0 .0 0 192.168 .10 .1 1 223.5 .5 .5 Enable Iperf Server You'll need to use the Finsh/MSH command on RT-Thread to enable the Iperf server, as shown as follows: msh />iperf -s -p 5001 -s Starting the server -p Monitoring the 5001 port. The installation file is located in `netutils/tools/jperf.rar` which is a portable application. the installation actually is the process of decompression to the new folder. Install the JPerf test software. Open `jperf.bat` and configure it according to the following steps: 1. Choose `Client` mode; 2. Enter the IP address that you obtained; 3. Modify the port number to 5001; 4. Click `run Lperf`! to start the test; 5. Wait for the test to finish. During testing, the test data is displayed on the shell interface and JPerf software. jperf test. Iperf Mode Use the ipconfig command on the PC's command prompt window to obtain the IP address of PC. Obtain IP address of the PC. The installation file is located in `netutils/tools/jperf.rar` which is a portable application. the installation actually is the process of decompression to the new folder. Install the JPerf test software. Open `jperf.bat` and configure it according to the following steps: 1. Choose `Server` mode; 2. Modify the port number to 5001; 3. Click run `Lperf`! to start the server; Enable the jperf server. Start the Iperf client. You'll need to use the Finsh/MSH command on RT-Thread to start the Iperf client, as shown as follows: msh />iperf -c -p 192.168 .12 .45 5001 -c Run as a client, connect to the specified server IP. -p Specify the TCP port of the server. During testing, the test data is displayed on the shell interface and JPerf software. Others NetIO is a tool for network performance testing on OS/2 2.x, Windows, Linux, and Unix. It uses packets of different sizes for network net throughput testing via TCP/UDP. NetIO RT-Thread currently supports NetIO TCP servers. Telnet Telnet Protocol is an application layer protocol, used in the Internet and local area networks with the form of virtual terminals, to provide two-way, text string-based interaction, it is part of the TCP/IP protocol suite and it is the standard protocol and primary method of Internet remote login service, which is often used for remote control of web servers and allows users to run the remote hosts on local hosts. RT-Thread currently supports the Telnet server, which, when successfully connected, will be remotely connected to the Finsh/MSH of device to remote control the device. tcpdump tcpdump is an RT-Thread-based gadget for capturing IP messages, and the data captured by packet can be saved through a file system or imported into a PC via a rdb tool, and parsed using wireshark software. RT-Thread Contact Info: | | | | Website Github Twitter Facebook Youtube