Re: About publish & subscribe mechanism in Bluetooth Mesh


Vikrant More <vikrant8051@...>
 

#define BT_MESH_MODEL(_id, _op, _pub, _user_data)                             \
{                                                                                                                     \
.id = (_id),                                                                                              \
.op = _op,                                                                                              \
.keys = { [0 ... (CONFIG_BT_MESH_MODEL_KEY_COUNT - 1)] =    \
BT_MESH_KEY_UNUSED },                                                \
.pub = _pub,                                                                                           \
.groups = {0xC000},                                                                               \
.user_data = _user_data,                                                                       \
}


I edit BT_MESH_MODEL macro definition from  #zephyr/include/bluetooth/mesh/access.h as  mentioned above,
so that every model get subscribed to 0xC000 group address.

I am able to publish (using bt_mesh_model_send() this API)data to Nodes which are subsribing to 0xC000.

For that I write button interrupt code as follow on Publisher node:

void board_button_1_pressed(void)
{
struct net_buf_simple *msg1 = NET_BUF_SIMPLE(2 + 4 + 1);
struct bt_mesh_msg_ctx ctx1 = {
.net_idx = 0,
.app_idx = 1,
.addr = 0xC000,
.send_ttl = BT_MESH_TTL_DEFAULT,
};

/* Bind to Health model */
bt_mesh_model_msg_init(msg1 , BT_MESH_MODEL_OP_2(0x82, 0x02) );

       net_buf_simple_add_u8(msg1,0x5A); // 0x55 == any data

if (bt_mesh_model_send(&vnd_models[0], &ctx1, msg1, NULL, NULL)) {
printk("Unable to send Vendor Button message\n");
}

}


After accessing one of the Subscriber serial terminal, it is conform that it is receiving something from src=0x0100(Publisher Unicast Address).

But I don't know where I will find 0x5A at subscriber side which is value send by Publisher ??



On Mon, Nov 27, 2017 at 1:17 PM, Johan Hedberg <johan.hedberg@...> wrote:
Hi Vikrant,

On Mon, Nov 27, 2017, Vikrant More wrote:
> How to send simple one byte of data from one node to another node which are
> provisioned using meshctl using unicast addresses ?

Mesh application payloads always start with a model-specific OpCode,
which is 1-3 bytes long. So if you want to send valid data you'd need to
do that in the context of a model, and in that case you'd use the
bt_mesh_model_publish() or bt_mesh_model_send() APIs.

If you want to discard the access layer formatting (i.e. OpCode +
payload) and send arbitrary "raw" application payloads, you could use
the "net-send" command that the mesh_shell app provides, however note
that this is purely for testing purposes and can't be used for building
final products.

> >>For subscribing you don't need anything >>special, except that a
> >>provisioner configures one or more >>subscription addresses to your
> >>models.
>
> How to achieve this using available meshctl commands ?

I'm not really familiar with meshctl, but looking at its source code it
seems to at least provide a "set-pub" command under the "config" submenu.
I don't see anything related to subscription there however. For testing
purposes you could also again use the Zephyr mesh_shell app since it can
send messages to itself. The shell provides "mod-pub" and "mod-sub-add"
commands for this.

Btw, if you want more help with meshctl, I recommend reaching out on
the BlueZ forums, i.e. the #bluez IRC channel on freenode and the
linux-bluetooth mailing list.

Johan

Join users@lists.zephyrproject.org to automatically receive all group messages.