Internet of Things
This article introduces the usage of RT-Thread NetUtils to help developers better use RT-Thread NetUtils components to solve problems encountered during network development.
When developing and debugging network-related products, some useful tools can often achieve twice the result with half the effort. Based on this application scenario, the RT-Thread NetUtils component has developed and encapsulated a series of concise and easy-to-use network tool sets to provide convenience for developers.
In order to facilitate users to develop network applications, RT-Thread has created a NetUtils component package for commonly used network tools. Through Env dynamic configuration, it is ready to use and effectively reduces resource usage.
As a collection of network tools, RT-Thread NetUtils includes Ping commands for testing and debugging, NTP tools for time synchronization, Iperf and NetIO for performance and bandwidth testing, and TFTP, a lightweight file transfer tool widely used in embedded systems, which facilitates file transfer between two devices over the network. In addition, RT-Thread also provides some advanced auxiliary tools for practical problems in development, such as Telnet tools that can remotely log in to RT-Thread Finsh/MSH Shell, and tcpdump, a network packet capture tool based on lwIP.
The following is the classification and introduction of RT-Thread NetUtils:
name
Classification
describe
Ping
Debugging Tests
The "ping" command can be used to check whether the network is connected, which can help us analyze and determine network failures.
NTP
Time Synchronization
Network Time Protocol
TFTP
File Transfer
TFTP is a simple protocol for transferring files, which is even lighter than FTP.
Iperf
Performance Testing
Tests maximum TCP and UDP bandwidth performance, reporting bandwidth, latency jitter, and packet loss
NetIO
Performance Testing
Tools for testing network throughput
Telnet
Remote Access
Can remotely log in to RT-Thread's Finsh/MSH Shell
tcpdump
Network debugging
tcpdump is a network packet capture tool based on lwIP for RT-Thread
Each gadget can be enabled/disabled independently using menuconfig, and Finsh/MSH usage commands are provided. First, open the Env tool, enter the BSP directory, enter menuconfig in the Env command line to enter the configuration interface, configure the project, and select the appropriate NetUtils function according to your needs, as shown in the figure
Note
Note: Ping and TFTP depend on lwIP. You need to enable lwIP dependency before they can be displayed.
Ping is a network diagnostic tool used to test whether data packets can reach a specific host through the IP protocol. It estimates the packet loss rate (packet loss rate) and the round-trip delay time (network delay) between the host and the data packet.
The Ping tool depends on lwIP. You need to enable the lwIP dependency in the Env tool before it can be seen. The steps are as follows:
Enable the Ping option in the NetUtils menu bar:
Ping supports access IP 地址
or 域名
, use Finsh/MSH command to test, the general use effect is as follows:
Ping Domain
Ping IP
NTP is the Network Time Protocol, which is a protocol used to synchronize the time of each computer in the network. The NTP client is implemented on RT-Thread. After connecting to the network, the current UTC time can be obtained and updated to the RTC.
Enable the NTP option in the NetUtils menu bar:
UTC time is also called the world unified time, world standard time, and international coordinated time. Beijing time is UTC+8 time, which is 8 hours more than UTC time, or 8 hours earlier.
The prototype of the function to obtain UTC time is: time_t time_t ntp_get_time(void)
, if the return value is greater than 0, the time is obtained successfully, and if it is equal to 0, it fails.
Sample code:
Local time has more time zone than UTC time, for example, Beijing time is in the Eastern Time Zone, which is 8 hours more than UTC time. menuconfig
You can set the current time zone in , the default is 8
.
The prototype of the function to obtain the local time is: time_t ntp_get_local_time(void)
, if the return value is greater than 0, the time is obtained successfully, and if it is equal to 0, it fails. The usage of this API is ntp_get_time()
similar to .
If the RTC device is enabled, you can also use the following commands and APIs to synchronize the local time of NTP to the RTC device.
The effects of the Finsh/MSH command are as follows:
The function prototype for synchronizing local time to RTC is: time_t ntp_sync_to_rtc(void)
, the return value is greater than 0 for success, and equal to 0 for failure.
Note
The NTP API method will occupy a large amount of thread stack when executed. Ensure that the stack space is sufficient (≥1.5K) when using it.
NTP API methods do not support reentrancy . Please be careful to lock them when using them concurrently.
TFTP (Trivial File Transfer Protocol) is a protocol in the TCP/IP protocol family used for simple file transfer between client and server. It provides simple and low-cost file transfer services. Its port number is 69. It is much lighter than the traditional FTP protocol and is suitable for small embedded products.
RT-Thread currently supports TFTP server.
The TFTP tool depends on lwIP. You need to enable the lwIP dependency in the Env tool before it can be seen. The steps are as follows:
Enable the TFTP option in the NetUtils menu bar:
Install TFTP Client
The installation files are located at netutils/tools/Tftpd64-4.60-setup.exe
. Please install the software before using TFTP.
Start TFTP Server
Before transferring files, you need to use the Finsh/MSH command on RT-Thread to start the TFTP server. The general effect is as follows:
Open the newly installed Tftpd64
software and configure it as follows:
1. Select Tftp Client
;
2. In Server interfaces
the drop-down box, be sure to select the network card that is in the same network segment as RT-Thread;
3. Fill in the IP address of the TFTP server. You can use ifconfig
the command to view it under MSH of RT-Thread;
4. Fill in the TFTP server port number, default:69
1. In Tftpd64
the software, select the file to be sent;
2. Remote File
The path where the server saves the file (including the file name). The option supports relative and absolute paths. Since RT-Thread turns on DFS_USING_WORKDIR
the option by default, the relative path is based on the directory currently entered by Finsh/MSH. Therefore, when using a relative path, be sure to switch the directory in advance;
3. Click Put
the button.
As shown in the figure below, send the file to the directory currently entered by Finsh/MSH. The relative path is used here :
Note
Note: If DFS_USING_WORKDIR
is not enabled and Remote File
is empty, the file will be saved in the root path.
1. In Tftpd64
the software, fill in the file path (including the file name) to be saved;
2. Remote File
The file path (including the file name) to be received by the server. The options support relative and absolute paths. Since RT-Thread has DFS_USING_WORKDIR
the option enabled by default, the relative path is based on the directory currently entered by Finsh/MSH. Therefore, when using a relative path, be sure to switch the directory in advance;
3. Click Get
the button.
As shown below, /web_root/image.jpg
save to local, here uses the absolute path :
Iperf is a network performance testing tool. Iperf can test the maximum TCP and UDP bandwidth performance, has multiple parameters and UDP characteristics, can be adjusted as needed, and can report bandwidth, delay jitter and packet loss.
Enable the Iperf option in the NetUtils menu bar:
Iperf uses a master-slave architecture, that is, one end is the server and the other end is the client. The Iperf software package we provide implements TCP server mode and client mode, and does not support UDP testing. The following will explain how to use the two modes in detail.
You need to use the Finsh/MSH command on RT-Thread to obtain the IP address. The general effect is as follows:
Write down the obtained IP address 192.168.12.71 (record according to the actual situation)
You need to use the Finsh/MSH command on RT-Thread to start the Iperf server. The effect is as follows:
-s means start as a server -p means listen on port 5001
Install JPerf test software
The installation file is located at netutils/tools/jperf.rar
, this is green software, the installation is actually a decompression process, just decompress it to a new folder.
Running jperf tests
Open jperf.bat
the software and configure it as follows:
1. Select Client
Mode;
2. Enter the IP address 192.168.12.71 you just obtained (fill in the actual address);
3. Change the port number to 5001;
4. Click run Lperf!
to start the test;
5. Wait for the test to end. During the test, the test data will be displayed on the shell interface and JPerf software.
Get the IP address of your PC
Use the ipconfig command in the command prompt window of the PC to obtain the IP address of the PC, and write down the obtained PC IP address as 192.168.12.45 (record according to the actual situation).
Install JPerf test software
The installation file is located at netutils/tools/jperf.rar
, this is green software, the installation is actually a decompression process, just decompress it to a new folder.
Start the jperf server
Open jperf.bat
the software and configure it as follows:
1. Select Server
Mode
2. Change the port number to 5001
3. Click run Lperf!
Start Server
Start Iperf Client
You need to use the Finsh/MSH command on RT-Thread to start the Iperf client. The effect is as follows:
-c means starting as a client, followed by the IP address of the PC running the server. -p means connecting to port 5001 and waiting for the test to end. During the test, the test data will be displayed on the shell interface and JPerf software.
In addition to the commonly used network tools mentioned above, RT-Thread also provides some practical network tools for development and debugging, such as NetIO tools, Telnet tools, and tcpdump tools.
NetIO is a tool for testing network performance on OS/2 2.x, Windows, Linux and Unix. It tests the network throughput using packets of different sizes via TCP/UDP.
RT-Thread currently supports NetIO TCP server.
For the usage of NetIO, please refer to the README in the component directory, which will not be described here.
Telnet protocol is an application layer protocol used in the Internet and local area network. It uses a virtual terminal to provide two-way interactive functions based on text strings. It is one of the TCP/IP protocol family and is the standard protocol and main method for Internet remote login services. It is often used for remote control of web servers and allows users to run tasks on remote hosts on local hosts.
RT-Thread currently supports Telnet server. After the Telnet client is successfully connected, it will remotely connect to the device's Finsh/MSH to achieve remote control of the device.
For the usage of Telnet, please refer to the README in the component directory, which will not be described here.
Tcpdump is a small tool based on RT-Thread for capturing IP packets. The captured data can be saved through the file system, or imported into the PC through the rdb tool and parsed using the wireshark software.
For the usage of tcpdump, please refer to the README in the component directory. I will not go into details here.
Last updated