Re: Complete Sample Demo for BluetoothMesh like Nordic Semiconductor "Light_Switch"

Johan Hedberg

Hi Vikrant,

On Wed, Dec 06, 2017, Vikrant More wrote:
static void publish(struct k_work *work)

static unsigned char onoff=0;
static unsigned char tid=0;
int err;

struct net_buf_simple *msg = NET_BUF_SIMPLE(2+4+2);

bt_mesh_model_msg_init(msg, OP_GEN_ONOFF_SET_UNACK);
net_buf_simple_add_u8(msg, onoff=onoff^0x01);
net_buf_simple_add_u8(msg, tid++);


This is not safe since the publishing buffer is not expected to be
allocated on the stack. It will cause a crash as soon as the Publish
Retransmit state is set to a non-zero value. I pointed this out earlier
to Steve and also tried to document it better:

So in your case you'd want to create the buffer when you define the
publication struct, i.e. something like:

static struct bt_mesh_model_pub pub = {
.msg = NET_BUF_SIMPLE(2+4+2),

And then before publishing you'd do the same bt_mesh_model_msg_init()
and net_buf_simple_add_u8() calls as you do now.

When I publish using *root_models[2] *then function
bt_mesh_model_publish(struct bt_mesh_model *model) from
execute properly after pressing the Button1 on nRF52840-PDK.

root_models[2] is server model.

Its publish address assigned by provisioner = 0xC000
It is subscribed to address = 0xC001

So all other nodes not changed their LED1 status when I pressed Button1
from any one of the Board since others are subscribed to 0xC001.

But when I hard-coded ctx.addr = 0xC001; in bt_mesh_model_publish(struct
bt_mesh_model *model) then ohter boards start to toggle LED1.
This looks like an issue with the provisioner (or how you use it) since
it seems it should also be setting the publication address to 0xc0001.

So I used root_model[4] i.e BT_MESH_MODEL_ID_GEN_ONOFF_CLI.

In this case, after pressing button, function bt_mesh_model_publish() returns
error as -> bt_mesh_model_publish: err:-49

On investigating, I found that this is because of

if (pub->addr == BT_MESH_ADDR_UNASSIGNED) {

That means Silicon Labs MESH APP does not assign any Public address to this
client model.
Ideally it should be 0xC001 since other NODEs are subscribed to it. Am I
right ?
Yes, sounds correct to me, i.e. this is an issue on the
provisioner/configuration client side.


Join to automatically receive all group messages.