Introduction
In the previous episode, we deployed a CoAP server on STM32WB. Now it’s time to complete the communication cycle by building a CoAP client that runs on a second STM32WB board. This episode focuses on sending CoAP GET requests to the server, interpreting responses, and understanding Thread mesh network routing.
Thread Mesh Communication Overview
Thread operates as a self-healing, IPv6-based mesh network using 6LoWPAN. Each node gets a unique IPv6 address. Communication between nodes follows standard IP routing but optimized for low power and wireless mesh reliability.
Key Concepts:
- Each node has a unique Mesh Local IPv6 address
- Communication uses UDP/IP over 6LoWPAN
- CoAP requests are sent to a server’s IP + URI path
Requirements
- Two STM32WB boards (e.g., Nucleo-WB55RG)
- STM32CubeIDE and Programmer installed
- STM32CubeWB firmware package (latest version)
Step 1: Locate the CoAP Client Example
Navigate to the CoAP Client example project inside the CubeWB package:
STM32Cube_FW_WB_Vx.x.x/Projects/P-NUCLEO-WB55.Nucleo/Applications/Thread/Coap_Client
This project initializes the Thread stack and periodically sends CoAP GET requests to a target IPv6 address.
Step 2: Configure the Target Server Address
Inside the CoAP Client example, open the file:
App/thread_app.c
Locate the section where the destination IPv6 address is configured:
static uint8_t aPeerAddr[] = {0xFD, 0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x00, 0x01,
0x02, 0x00, 0x00, 0xFF, 0xFE, 0x00, 0x12, 0x34};
Replace this with the actual Mesh Local IPv6 address of your server node. You can retrieve this from the server’s UART output log, often shown as:
Mesh Local EID: fdde:adbe:...:1234
Step 3: Configure the Resource Path
The CoAP request path is configured in the client as:
static char aUriPath[] = "light";
This should match the URI exposed by your server, e.g., /light.
Step 4: Import, Build, and Flash the Project
- Open STM32CubeIDE
- Import the CoAP Client project
- Update the IPv6 address and URI path
- Build the project
- Flash it to the second STM32WB board using ST-LINK or STM32CubeProgrammer
Step 5: Observe Communication
Open a serial terminal for both server and client boards. After startup, the client will attempt to send periodic CoAP GET requests to the server.
Expected Output (Client side):
[Thread] Device role: Router
[CoAP] Sending GET to fdde:adbe:...:1234 on /light
[CoAP] Response received: {"light":"on"}
Expected Output (Server side):
[CoAP] Received GET /light from fdde:adbe:...:5678
[CoAP] Responded with payload {"light":"on"}
Technical Notes
- Each CoAP transaction uses a unique token for matching request/response
- Thread devices operate in specific roles — the client will act as Router if it’s not the network leader
- Ensure PAN ID and channel match on both boards (configurable in
app_conf.h) - You can enable debugging logs by defining
APP_DBGin the compiler flags
Conclusion
You’ve now successfully created a CoAP client on STM32WB that communicates with a CoAP server over a Thread mesh network. This validates bidirectional data exchange over Thread and shows how easily STM32WB can manage IPv6 and CoAP stack layers. In the next episode, we’ll expand on this. We’ll be creating custom CoAP resources. We’ll handle POST requests to control on-board peripherals.

Leave a comment