How to extend one BLE-Mesh model's functionality to another.?

Hi,

I am working on a multiple custom models, wherein I need one model to extend the functionality of another model.

I was analyzing through nCS provided "Chat" sample code, where I saw that Chat client model extends to health server model as an example.

To extend first Health model handlers were initialized as in:

static void attention_on(struct bt_mesh_model *mod)
{
	attention = true;
	k_work_reschedule(&attention_blink_work, K_NO_WAIT);
}

static void attention_off(struct bt_mesh_model *mod)
{
	/* Will stop rescheduling blink timer */
	attention = false;
}

static const struct bt_mesh_health_srv_cb health_srv_cb = {
	.attn_on = attention_on,
	.attn_off = attention_off,
};

static struct bt_mesh_health_srv health_srv = {
	.cb = &health_srv_cb,
};

BT_MESH_HEALTH_PUB_DEFINE(health_pub, 0);

Then The health model was initialized along with Chat client as in:

static struct bt_mesh_elem elements[] = {
	BT_MESH_ELEM(
		1,
		BT_MESH_MODEL_LIST(
			BT_MESH_MODEL_CFG_SRV,
			BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub)),
		BT_MESH_MODEL_LIST(BT_MESH_MODEL_CHAT_CLI(&chat))),
};

My questions are:

1. Suppose I want to call attention on when a chat message is received. How do I do this & what changes I need to make in code..?

2. In my custom models, how do exchange data between models..?

3. How do I trigger an extending model API from the main model API..?

Thanks,

  • Hi,

    What version of the SDK are you using?

    I would recommend you to look through these documentation:

    Chat Client Model

    Chat sample walk-through

    Vendor model development overview

    Also have a look at this thread.

  • Hi,


    These absolutely have no data regarding model extension.

    My questions are:

    1. Suppose I want to call attention on when a chat message is received. How do I do this & what changes I need to make in code..?

    2. In my custom models, how do exchange data between models..?

    3. How do I trigger an extending model API from the main model API..?

    I am looking for code changes, I am aware of the theory on extension.

    As an example, help me with an use case, suppose i want to trigger attention On API (From health model) when I receive a chat message (In chat client model), How can I do so..?

    I am aware of the initial loop, looking more towards API changes now.

    Thanks,

  • Hi,

    It seems to have been some confusion. Chat client doesn't extend health server. They are just instantiated on the same element. The extended models will share a subscription list and this is the only thing that the mesh stack will handle for you. This is done through bt_mesh_model_extend API. Sharing a message behaviour is up to implementer. E.g. in nRF Connect SDK we do it through callbacks. For example, you can look at Generic Level and Generic Power Level servers implementation, where Generic Power Level Server models implements callbacks of Generic Level Server model to intercept Generic Level messages.

    Regadring the questions:

    1. No, you can't do that. There is no such API in health server. You need to have a health client on the same device and use bt_mesh_health_attention_set API to do that. And you need to call this API from chat model message handler.
    2. As mentioned above, it is up to implementor. We use callbacks to propagate message data.
    3. Send a message to a base model. If a model is extended, this should trigger behaviour of the model that extends this one. E.g. if you send a message to a Generic Level Server model, when it is extended by Generic Power Level model, this will change Generic Power Level state value.

Related