Skip to content

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.

image1

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.

image2

Wait for the installation to complete.

image3

image4

After waiting for a while, when the interface below appears, it indicates that the download is complete, and you can start preparing to compile the code.

image5

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.

You can drag your project into VS-Code to open the code.

image6

Then select ESP-IDF below and choose the ESP-IDF Version 5.4 environment you just downloaded.

image7

Select the just-downloaded version 5.4.

image8

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.

IMG_256

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:


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.

image10

Figure 1

(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.

image11

Figure 2

(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.

For ot_rcp, the following explanation is provided:

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.

image12

Figure 3

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.

image13

Figure 4

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.

{width="5.763888888888889in" height="4.263888888888889in"}

Figure 5

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.

IMG_256

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.

image16

For the development boards of the Advance series, the main controller is ESP32-S3.

① Select the previously downloaded ESP-IDF V5.4

② Select the serial port you connected to your computer

③ Select the main controller ESP32-S3

④ First, compile the code, wait for the compilation to complete, ensure the code is error-free, and then proceed to step 5 - upload the code

⑤ Upload the code to the Advance series development boards

⑥ It is recommended to complete step 4 first, then directly proceed to step 6, compile, burn, and open the monitor. This way, everything can be done in one step.

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.

image17

For ESP32-C6 / ESP32-H2

① Select the previously downloaded ESP-IDF V5.4

② Select the serial port you connected to your computer

③ Select the main control ESP32-C6 / ESP32-H2

④ First, compile the code, wait for the compilation to complete, ensure the code is error-free, then proceed to step 5 - upload the code

⑤ Upload the code to the wireless module

⑥ It is recommended to complete step 4 first, then directly proceed to step 6, compile, burn, and open the monitor. This way, everything can be done in one step.

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

image18

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.

IMG_256

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.

image20

For the development boards of the Advance series, the main controller is ESP32-S3.

① Select the previously downloaded ESP-IDF V5.4

② Select the serial port you connected to your computer

③ Select the main controller ESP32-S3

④ First, compile the code, wait for the compilation to complete, ensure the code is error-free, and then proceed to step 5 - upload the code

⑤ Upload the code to the Advance series development boards

⑥ It is recommended to complete step 4 first, then directly proceed to step 6, compile, burn, and open the monitor. This way, everything can be done in one step.

Flash the ot_cli 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.

image21

For ESP32-C6 / ESP32-H2

① Select the previously downloaded ESP-IDF V5.4

② Select the serial port you connected to your computer

③ Select the main control ESP32-C6 / ESP32-H2

④ First, compile the code, wait for the compilation to complete, ensure the code is error-free, then proceed to step 5 - upload the code

⑤ Upload the code to the wireless module

⑥ It is recommended to complete step 4 first, then directly proceed to step 6, compile, burn, and open the monitor. This way, everything can be done in one step.

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.

image22

Step 3: Combine the border router and the sub-device respectively, and connect them to the computer, as shown in the following figure.

IMG_256{width="5.020833333333333in" height="3.6875in"}

Step 4: Set up the border router

Open the serial port assistant we provide. It will be able to assist you very well in using it. (Of course, if you have a better serial port assistant, you can also use that.)

image24

Double-click to open this serial port assistant

image25

image26

Select the serial port corresponding to your size of product, and then open the serial port.

image27

Connect the 7.0-inch development board to the computer via UART, and transmit the command string "wifi connect -s -p " to configure the Wi-Fi connection.

image28

Sequentially transmit the command strings "dataset init new", "dataset commit active", "ifconfig up", and "thread start" to form a Thread network.

image29

image30

![image31](./assets/images/advance_thread_C6H2/image31.webp

image32

The border router exists as the leader in the Thread network, and the command string "state" can be used to check its status.

image33

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.)

image34

image35

Step 5: 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.)

The xxx mentioned here was obtained on the 7-inch device just now. You can simply copy it from there.

image36

image37

Set the active network data on the CLI device using the command "dataset commit active".

image38

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.

image39

image40

After the thread network settings are completed, you can input "state" to check the current status of the device, which indicates the current role it is in.

image41

At this point, it is a successful state for the distribution network. That is to say, both parties have been properly matched. Then, if you observe the serial port information on the 7-inch end, you can see the relevant information indicating successful network connection, and an ID number has been randomly assigned to the 3.5-inch end.

image42

Of course, you can also check it out. On the 7-inch device, ping the 3.5-inch device to see if you can get a response.

As shown in the picture, this indicates a successful ping.

image43

Step 6: 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.

image44

The information therein represents:

image45

The first line "fd35:f22a:f22f:e25:0:ff:fe00:6000" is the unique local multicast address for the Thread network, used to send multicast data such as network instructions and configuration updates to all routers within the network;

The second line "fd35:f22a:f22f:e25:3a71:c947:a656:a4e3" is the unique local unicast address for the Thread device, serving as the core communication identifier for the device, enabling unicast communication between devices and cross-network data transmission (such as cloud reporting);

The third line "fe80::cb3:1699:d971:144e" is a link-local unicast address, used only for device initialization communication within the Thread network (such as neighbor discovery and access negotiation), and cannot be accessed across networks.

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).

(Both ends need to enable UDP, and both ends need to bind port numbers, and they should be set differently)

(Here, the 7-inch display on the left is bound to 002)

(Here, the 3.5-inch display on the right is bound to 001)

image46

image47

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)".

(Here, I first input the ipaddr to obtain the 7-inch IPv6 address, and then input the sending command on the 3.5-inch end. Send 123456 to the 7-inch device.)

You can see that the sending was successful!

image48

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.

And on the 7-inch display, one can see the information sent from the 3.5-inch display, as well as the 3.5-inch device\'s own IPv6 address.

image49

Note: It is also possible for the child side or the router to send data, and for the leader side to receive it.