Lesson 10 Developing Thread Wireless Mesh Network Technology for CrowPanel Advance AI Display¶
1. Environment Configuration:¶
The code for this lesson all uses version v5.4 of the IDF (Espressif IoT Development Framework), so it is necessary to download it in VSCode first.
Click on the following options in sequence.
After selecting the installation path, click "Configure Tools".
Note: The installation path of the components must be in the "tools" folder under the installation path of the IDF-IDE.
Wait for the installation to complete.
Tips: If you have downloaded other versions before, you only need to download version v5.4 of the IDF. After that, switch to version v5.4 and then select the chip model.
Right-click on the project, select VSCode, and open the code that needs to be run.
Click the following options in sequence.
Switch to version v5.4
2. Hardware Composition:¶
(1) Two CrowPanel Advance AI Displays
(2) Two wireless modules (ESP32-H2 or ESP32-C6)
(3) Two Type-C cables
In this tutorial, a combination of a 7.0-inch display screen and a wireless module(ESP32-H2 or ESP32-C6) is used as the border router, and a combination of a 3.5-inch display screen and another wireless module (ESP32-H2 or ESP32-C6) is used as the sub-device. The code provided in the link of this lesson corresponds to this hardware composition.
Note: Before connecting the devices, switch the select function keys of the 7.0-inch, 5.0-inch or 4.3-inch development board to 01.
3. Software Packages:¶
ot_brt --- The code for the host in the border router (to be flashed into the ESP32-S3 on the development board)
ot_rcp --- The code for the RCP in the border router (to be flashed into the ESP32-H2 or ESP32-C6 on the development board)
ot_cli --- The code for the CLI device (to be flashed into the ESP32-H2 or ESP32-C6 on the development board)
ot_uart --- The serial port forwarding code for the CLI device side (to be flashed into the ESP32-S3 on the development board)
For the relevant code comments, please refer to the files.
The specific content of ot_brt:
Figure 1
Figure 2
ot_brt:
(1) As shown in Figure 1: Configure the way the host connects to the RCP side. Use UART connection. The following is the configuration of the serial port. The specific ports and IOs used should be based on the actual situation. The parameters such as the baud rate should be consistent with the configuration of the RCP side.
(2) As shown in Figure 2: Configure the way the CLI commands connect to the host. Use UART connection. The specific ports and IOs used should be based on the actual situation, which is convenient for configuring the Thread network using CLI commands later.
(3) The Wi-Fi of the border router can use the automatic startup mode CONFIG_OPENTHREAD_BR_AUTO_START. After enabling it, it will call the SSID and password stored in NVS or in Kconfig. By default, the automatic mode is not enabled, and the SSID and password should be configured through CLI commands.
Figure 3
ot_rcp:
As shown in Figure 3: Configure the usage mode of the radio. When the RCP side is connected to the host side, use the UART mode. The specific ports and IOs used should be based on the actual situation, and parameters such as the baud rate should be consistent with the configuration of the host side.
Figure 4
ot_cli:
As shown in Figure 4: Configure the way the radio is used. When connecting the CLI commands to the host, use the UART mode. The specific ports and I/O pins to be used should be determined according to the actual situation.
Figure 5
ot_uart:
As shown in Figure 5: Configure the serial port forwarding settings through the sdkconfig. In this device, IO1 of the ESP32-S3 is set as the CLI UART Tx pin, and IO2 is set as the CLI UART Rx pin.
4. Specific operation steps¶
Step 1: Flash the ot_brt code into a 7.0-inch display screen and the ot_rcp code into a wireless module (ESP32-H2 or ESP32-C6), and combine them to form a border router. (Note: If the RCP side cannot be recognized, the code on the host side will restart continuously.)
Connect the devices to the computer respectively.
Flash the ot_brt code into the 7.0-inch display screen. After switching to version idf_v5.4, perform the following operations to flash the code onto the development board.
Flash the ot_rcp code into the wireless module (ESP32-H2 or ESP32-C6). After switching to version idf_v5.4, perform the following operations to flash the code onto the development board.
Note: Press and hold the "boot" button while briefly pressing the "reset" button to put the chip into the programming mode, and then click the "Flash" button.
The interface after the burning is completed
Step 2: Flash the ot_uart code into the 3.5-inch display screen, and flash the ot_cli code into another wireless module (ESP32-H2 or ESP32-C6) to serve as a sub-device or router.
Connect the devices to the computer respectively.
Flash the ot_uart code into the 3.5-inch display screen. After switching to the idf_v5.4 version, perform the following operations to flash the code onto the development board.
Flash the ot_rcp code into the wireless module (ESP32-H2 or ESP32-C6). After switching to the idf_v5.4 version, perform the following operations to flash the code onto the development board.
Note: Press and hold the "boot" button and briefly press the "reset" button at the same time to put the chip into the programming mode, and then click the option for flashing.
The interface when the burning process is completed.
Step 3: Combine the border router and the sub-device respectively, and connect them to the computer, as shown in the following figure.
Step 4: Set up the border router
Connect the 7.0-inch development board to the computer via UART, and transmit the command string "wifi connect -s
Sequentially transmit the command strings "dataset init new", "dataset commit active", "ifconfig up", and "thread start" to form a Thread network.
The border router exists as the leader in the Thread network, and the command string "state" can be used to check its status.
Use the command string "dataset active -x" to obtain the Thread network dataset or "networkkey" to obtain the network key, so that other CLI devices can join the Thread network conveniently. (Choose one of them.)
Step5: Set up the child device or router:
Connect the 3.5-inch development board to the computer via UART and open the serial port assistant.
Submit the network dataset using the command "dataset set active xxx" or the network key using the command "dataset networkkey xxx". (Choose one of them.)
Set the active network data on the CLI device using the command "dataset commit active".
Use "ifconfig up" and "thread start" in sequence to form a Thread network.
The CLI device acts as a child device or a router in the Thread network.
Step6: Send data from the leader side to the child side:
Obtain the IPv6 address of the receiving child side; the child side can send the CLI command "ipaddr" via UART, which can output the IPv6 address of each board.
On the receiving child side, use the CLI command "udp open" to enable the UDP function, and use "udp bind :: xxxxx" to bind the port (here, the custom port number of the child side is set as 001).
On the sending leader side, use the CLI command to enable the UDP function.
Then use the command "udp send xxx (the ML-EID address in the IPv6 address) xxx (port number) xxx (the content of the information to be sent)".
After a successful sending, the Thread device at the corresponding address and the corresponding port number (in this case, the receiving child side) will be able to receive the data.
Note: It is also possible for the child side or the router to send data, and for the leader side to receive it.