I recently bought some IoT devices that communicate using Matter over Thread. I had issues with connection stability to battery powered devices that are further away from the Border Router, so let's build a "range extender" using an ESP32-H2.
Different Thread device types
After I have set up my Thread powered devices, I quickly learned that there are basically two distinct types of Thread devices:
- Full Thread Device (FTD)
FTDs support all features of Thread, including acting as a mesh router, at the cost of more power usage. These devices are most likely connected to mains power. - Minimal Thread Device (MTD)
MTDs only support a minimal set of Thread features to minimize power usage. Most battery powered devices are MTDs.
To save energy, MTDs are restricted from becoming a mesh router in the network. This also means, that you will quickly lose reception if your Thread network only consist of MTDs and you place some of them far away from the border router.
To mitigate this, you can either buy some mains powered devices such as smart wall plugs or home hubs that can join your network - or you program a cheaper ESP32-H2 to be a Full Thread Device!
Building the firmware
For the firmware, I mostly used the example project by Espressif to get started and only slightly modified some configuration options, such as enabling the status LED and automatically starting the OpenThread software on the device.
Installing on your ESP32-H2
Flashing the firmware
- Download the latest firmware
- Flash the firmware onto your ESP:
Replace
esptool.py --chip esp32h2 --port /dev/YOUR_TTY_PORT --baud 460800 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 48m --flash_size detect 0x0 bootloader.bin 0x8000 partitions.bin 0x10000 firmware.bin
/dev/YOUR_TTY_PORT
with your actual USB serial port. - Connect to the board via USB serial (e.g. with
screen
) - Verify that the firmware booted by running the
version
command. It should display something similar toesp32-thread-router/67c1de1eeb-005c5cefc; esp32h2; 2025-01-20 20:53:51 UTC
Connecting to your Thread network
Initially, the firmware will create a new Thread network. To connect to your existing Thread network, you will need an active dataset TLV. This is usually a long string starting with 0e0...
. In Home Assistant, you can find that string under Settings / Devices & Services / Thread / Configure / 🛈.
The firmware will light up the RGB LED based on the Thread state.
- Red: Detached. The device is not connected to any Thread network.
- Purple: Leader. The device is the leader of (probably its own) Thread network.
- Green: Client. The device is a client in a network but does not act as a router.
- Blue: Router. The device is a router in a network. (This is what we want)
Alternatively, you can query the device state with the state
command.
To connect your device to your Thread network, set the active dataset with
dataset set active 0e0...
If everything works and the ESP switches to the client or router state after a short amount of time, you can persist the dataset to flash:
dataset commit active
You can now deploy the ESP somewhere in your Thread network. To extend the mesh network even further, you can add more FTDs. The Thread network will automatically figure out the best routes for each device based on network conditions.