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.

RT-Thread online packages
  -> IoT - internet of things
    -> netutils: Networking utilities for RT-ThreadcopymistakeCopy Success

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:

-> RT-Thread Components
  -> Network stack
    -> light weight TCP/IP stack
      -> Enable lwIP stackcopymistakeCopy Success

Enable the Ping option in the NetUtils menu bar:

RT-Thread online packages
  -> IoT - internet of things
    -> netutils: Networking utilities for RT-Thread
    [*] Enable Ping utilitycopymistakeCopy Success

Ping supports access IP 地址 or 域名, use Finsh/MSH command to test, the general use effect is as follows:

  • Ping Domain

msh />ping rt-thread.org
60 bytes from 116.62.244.242 icmp_seq=0 ttl=49 time=11 ticks
60 bytes from 116.62.244.242 icmp_seq=1 ttl=49 time=10 ticks
60 bytes from 116.62.244.242 icmp_seq=2 ttl=49 time=12 ticks
60 bytes from 116.62.244.242 icmp_seq=3 ttl=49 time=10 ticks
msh />
copymistakeCopy Success
  • Ping IP

msh />ping 192.168.10.12
60 bytes from 192.168.10.12 icmp_seq=0 ttl=64 time=5 ticks
60 bytes from 192.168.10.12 icmp_seq=1 ttl=64 time=1 ticks
60 bytes from 192.168.10.12 icmp_seq=2 ttl=64 time=2 ticks
60 bytes from 192.168.10.12 icmp_seq=3 ttl=64 time=3 ticks
msh />
copymistakeCopy Success

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:

RT-Thread online packages
  -> IoT - internet of things
    -> netutils: Networking utilities for RT-Thread
    [*] Enable NTP(Network Time Protocol) clientcopymistakeCopy Success

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:

#include <ntp.h>

void main(void)
{
    time_t cur_time;

    cur_time = ntp_get_time();

    if (cur_time)
    {
        rt_kprintf("NTP Server Time: %s", ctime((const time_t*) &cur_time));
    }
}copymistakeCopy Success

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. menuconfigYou 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:

msh />ntp_sync
Get local time from NTP server: Sat Feb 10 15:22:33 2018
The system time is updated. Timezone is 8.
msh />copymistakeCopy Success

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:

-> RT-Thread Components
  -> Network stack
    -> light weight TCP/IP stack
      -> Enable lwIP stackcopymistakeCopy Success

Enable the TFTP option in the NetUtils menu bar:

RT-Thread online packages
  -> IoT - internet of things
    -> netutils: Networking utilities for RT-Thread
    [*] Enable TFTP(Trivial File Transfer Protocol) servercopymistakeCopy Success
  • 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:

msh />tftp_server
TFTP server start successfully.
msh />copymistakeCopy Success

Open the newly installed Tftpd64software and configure it as follows:

1. Select Tftp Client;

2. In Server interfacesthe 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 ifconfigthe command to view it under MSH of RT-Thread;

4. Fill in the TFTP server port number, default:69

1. In Tftpd64the software, select the file to be sent;

2. Remote FileThe 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_WORKDIRthe 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 Putthe 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_WORKDIRis not enabled and Remote Fileis empty, the file will be saved in the root path.

1. In Tftpd64the software, fill in the file path (including the file name) to be saved;

2. Remote FileThe 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_WORKDIRthe 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 Getthe button.

As shown below, /web_root/image.jpgsave to local, here uses the absolute path :

msh /web_root>ls           ## 查看文件是否存在
Directory /web_root:
image.jpg           10559
msh /web_root>copymistakeCopy Success

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:

RT-Thread online packages
  -> IoT - internet of things
    -> netutils: Networking utilities for RT-Thread
    [*] Enable iperf-liked network performance toolcopymistakeCopy Success

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.

Get IP address

You need to use the Finsh/MSH command on RT-Thread to obtain the IP address. The general effect is as follows:

msh />ifconfig
network interface: e0 (Default)
MTU: 1500
MAC: 00 04 9f 05 44 e5
FLAGS: UP LINK_UP ETHARP
ip address: 192.168.12.71
gw address: 192.168.10.1
net mask  : 255.255.0.0
dns server #0: 192.168.10.1
dns server #1: 223.5.5.5copymistakeCopy Success

Write down the obtained IP address 192.168.12.71 (record according to the actual situation)

Start Iperf Server

You need to use the Finsh/MSH command on RT-Thread to start the Iperf server. The effect is as follows:

msh />iperf -s -p 5001copymistakeCopy Success

-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.batthe software and configure it as follows:

1. Select ClientMode;

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.batthe software and configure it as follows:

1. Select ServerMode

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:

msh />iperf -c 192.168.12.45 -p 5001copymistakeCopy Success

-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

Assoc. Prof. Wiroon Sriborrirux, Founder of Advance Innovation Center (AIC) and Bangsaen Design House (BDH), Electrical Engineering Department, Faculty of Engineering, Burapha University