Introduction
Your STM32WB board is ready. Your development environment is also set up. It’s now time to take a significant step forward by creating your first Thread-based application. In this episode, we’ll create a simple CoAP (Constrained Application Protocol) server using the Thread stack. We will understand how Thread networking works in practice on STM32WB.
Understanding CoAP in Thread Networks
CoAP is a lightweight protocol designed for constrained devices and is widely used in IoT networks. It functions similarly to HTTP but is optimized for UDP and smaller code footprints. In Thread networks, CoAP plays a key role in enabling device-to-device communication through GET, POST, PUT, and DELETE methods.
Why CoAP?
- Efficient use of bandwidth (runs over UDP)
- Low memory and processing requirements
- Supports asynchronous communication
- Designed specifically for constrained environments like Thread networks
Exploring the STM32CubeWB CoAP Example
STMicroelectronics provides ready-to-use CoAP server/client examples in the STM32CubeWB firmware package. Let’s walk through how to use and understand these examples.
Step 1: Locate the Example
After extracting the STM32CubeWB firmware package, navigate to:
STM32Cube_FW_WB_Vx.x.x/Projects/P-NUCLEO-WB55.Nucleo/Applications/Thread/Coap_Server
This folder contains the source code, project files for STM32CubeIDE, and binaries.
Step 2: Open the Project in STM32CubeIDE
- Launch STM32CubeIDE
- Go to File > Import > Existing Projects into Workspace
- Select the
Coap_Serverfolder - Click Finish to import the project
Step 3: Build and Flash the Firmware
- Click the hammer icon or Project > Build Project to compile the firmware
- Connect the board and select Run > Debug As > STM32 MCU Application
- This will program the board with the CoAP server firmware
Step 4: Monitor the Output
Use a serial terminal (like Tera Term or PuTTY) and connect to the board’s virtual COM port. Set the baud rate to 115200. You should see Thread network initialization logs and CoAP server readiness.
Understanding the Application Flow
The CoAP server example typically does the following:
- Initializes the Thread protocol stack
- Forms or joins a Thread network
- Starts a UDP-based CoAP server
- Waits for incoming CoAP requests (e.g., GET on
/light)
Thread Role Assignment
The board usually starts as a router or leader if it’s the first node in the network. You can check the assigned role in the serial output.
Sample Log Output:
[Thread] Device role: Leader
[CoAP] Server started on port 5683
[CoAP] Listening on resource: /light
Testing the CoAP Server
You can test the CoAP server using a PC tool like coap-client (from libcoap) or mobile apps like CoAP Explorer.
Example GET Command:
coap-client -m get coap://[THREAD_DEVICE_IP]/light
Expected Response:
2.05 Content
{"light":"on"}
This confirms the CoAP server is working and reachable over the Thread network.
Conclusion
In this episode, you learned how to build and run your first Thread application using the STM32WB. We explored how a CoAP server operates. We also looked into how to flash a pre-existing example and test it using CoAP tools. This step proves your development environment is fully functional. It also shows that you’re prepared to start building more complex Thread-based applications.
In the next episode, we will create a CoAP client. We will form a complete communication cycle between two STM32WB boards using the Thread protocol.

Leave a comment