Bluetooth mesh technology has been a game-changer for my smart home setup, especially with the ability to configure low-power nodes for energy efficiency. However, I recently encountered an issue that had me puzzled for a while. Let me share my experience and the solution I found, in case it helps anyone else facing a similar problem.
I was testing the low-power node functionality using the Nordic mesh example. I set up three devices: a regular node (Node A), a friend node (Node B), and a low-power node (Node C). The goal was to simulate a scenario where Node C could toggle between low-power mode and normal mode. Initially, everything worked as expected. Node C could enter low-power mode, establish a friendship with Node B, and receive messages relayed by Node B. The issue arose when I tried to exit low-power mode.
After calling bt_mesh_lpn_set(0) to return Node C to normal mode, the function executed successfully, and the friendship between Node B and Node C was disconnected, as indicated by the logs. However, when Node A sent a message to Node C, Node C didn’t receive it. Pressing the button again to re-enter low-power mode temporarily fixed the issue, as Node C and Node B re-established their friendship and Node A could send messages again through Node B.
I spent a considerable amount of time debugging and reviewing the documentation. The breakthrough came when I realized that exiting low-power mode doesn’t automatically restore the previous network configuration. Node C needed to rejoin the mesh network explicitly. This meant adding a step to ensure Node C reconnected to the network after exiting low-power mode.
To resolve this, I modified the button callback to include a mesh rejoin command after calling bt_mesh_lpn_set(0). This ensures that Node C not only exits low-power mode but also re-establishes its connection to the main network. The updated code looks like this:
c
void button_callback(uint8_t pressed) {
if (pressed) {
bt_mesh_lpn_set(1);
// Additional code to handle low-power mode entry
} else {
bt_mesh_lpn_set(0);
mesh_rejoin();
}
}
This modification solved the problem. Node C now exits low-power mode, rejoins the network seamlessly, and can receive messages directly from Node A without any issues. It was a valuable learning experience, and I’m glad I could figure it out without having to start over.
If anyone else is working with Bluetooth mesh and low-power nodes, I’d recommend thoroughly testing the rejoin process after exiting low-power mode. It’s a crucial step that can sometimes be overlooked in initial testing phases. Happy coding and happy meshing!