Unable to set Appkey for generic server model


Mani Sadhasivam
 

Hello,

My objective is to use 96Boards carbons running Zephyr to form a mesh network for publishing sensor data. For testing purposes, I am using Generic ON/OFF server model for sending the sensor data to all nodes in the network, later this will get replaced by Sensor server model.

However, after provisioning the node using `meshctl` and binding AppKey to the model, publishing sensor data from node results in the below error:

[bt] [ERR] model_send: Model not bound to AppKey 0x0001

Thread used for publishing sensor data:

void temp_work_thread(struct k_work *work)
{
        if (node_addr == BT_MESH_ADDR_UNASSIGNED)
                return;

        struct net_buf_simple *msg = NET_BUF_SIMPLE(3 + 4);
        struct bt_mesh_msg_ctx ctx = {
                .net_idx = 0,
                .app_idx = 1,
                .addr = BT_MESH_ADDR_ALL_NODES,
                .send_ttl = BT_MESH_TTL_DEFAULT,
        };

        bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP);
        net_buf_simple_add_u8(msg, 1);

        if (bt_mesh_model_send(&root_models[0], &ctx, msg, NULL, NULL)) {
                printk("Unable to send sensor message\n");
                return;
        }

        printk("Sensor message sent with OpCode 0x%08x\n", BT_MESH_MODEL_OP);
 
}

Meshctl commands for provisioning and binding AppKey:

discover-unprovisioned on
provision 0108  # Node address 0108
menu config
target 0108
appkey-add 1
bind 0 1 1000 # bind AppKey 1 to model 1000 of 0th element

Above commands seems to succeed with below debug message:

[Zephyr-Node-0108]# target 0108
Configuring node 0108
[config: Target = 0108]# target 0108[config: Target = 0108]# appkey-add 1
GATT-TX: 00 f4 c2 c3 a1 79 49 50 dd 24 66 ea ac 62 e3 76 
GATT-TX: 8d 86 c3 53 dd ca b1 76 2e 21 0c aa 5c c8 
GATT-TX: 00 f4 56 51 ac b5 41 23 5c 15 44 f4 40 68 04 92 
GATT-TX: 35 5f e0 33 34 1a 32 99 00 01 b5 67 ed c0 
GATT-RX: 00 f4 fb 34 d9 5b 37 66 66 0f 1b 3b d0 ca e5 24 
GATT-RX: 70 92 fd 94 3c 44 6c 42 e6 
GATT-RX: 00 f4 33 91 bd 9f b5 37 2d ae 01 5a c8 67 00 c0 
GATT-RX: fa 5f 34 fc e4 53 c9 da 15 
Node 0108 AppKey Status Success
NetKey 000, AppKey 001
[config: Target = 0108]# bind 0 1 1000
GATT-TX: 00 f4 25 40 41 a2 09 fb 01 8f d1 be 2c e3 1b 0b 
GATT-TX: 13 e3 ac 38 ea f9 74 c7 99 a9 33 
GATT-RX: 00 f4 a3 1b e3 71 55 5c 0b a6 d1 6f a2 6f 80 62 
GATT-RX: 84 d6 26 a9 61 49 0a 73 ad 31 bc 04 
Node 0108 Model App Status Success
Element 0108 AppIdx 001
ModelId 1000
[config: Target = 0108]# 

Can anyone please clarify what is going wrong?

Branch used: Latest Master branch

Thanks in advance!

-Mani


Johan Hedberg
 

Hi Mani,

On Sat, Dec 23, 2017, Mani Sadhasivam wrote:
[bt] [ERR] model_send: Model not bound to AppKey 0x0001

Thread used for publishing sensor data:

void temp_work_thread(struct k_work *work)
{
if (node_addr == BT_MESH_ADDR_UNASSIGNED)
return;

struct net_buf_simple *msg = NET_BUF_SIMPLE(3 + 4);
struct bt_mesh_msg_ctx ctx = {
.net_idx = 0,
.app_idx = 1,
.addr = BT_MESH_ADDR_ALL_NODES,
.send_ttl = BT_MESH_TTL_DEFAULT,
};

bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP);
net_buf_simple_add_u8(msg, 1);

if (bt_mesh_model_send(&root_models[0], &ctx, msg, NULL, NULL)) {
A couple of things come to mind here:

Is root_models[0] really the model that's supposed to do the publishing?
It's often the Configuration Server Model, which would explain the error
you're getting. You didn't show the definition of your models array, so
I'm just guessing here.

Also, if this is really a formal publish message you're sending, you
should be using the bt_mesh_model_publish() API instead of
bt_mesh_model_send(). The latter is intended mainly for client model
messages as well as for the server's responses to those, and it doesn't
take into consideration things like the Model Publish Retransmit state
or that you're actually publishing using the configured publication
state (correct app key, destination address, TTL, etc).

Johan


Mani Sadhasivam
 

Hi Johan,

On Sat, Dec 23, 2017 at 5:21 PM, Johan Hedberg <johan.hedberg@...> wrote:
Hi Mani,

On Sat, Dec 23, 2017, Mani Sadhasivam wrote:
> [bt] [ERR] model_send: Model not bound to AppKey 0x0001
>
> Thread used for publishing sensor data:
>
> void temp_work_thread(struct k_work *work)
> {
>         if (node_addr == BT_MESH_ADDR_UNASSIGNED)
>                 return;
>
>         struct net_buf_simple *msg = NET_BUF_SIMPLE(3 + 4);
>         struct bt_mesh_msg_ctx ctx = {
>                 .net_idx = 0,
>                 .app_idx = 1,
>                 .addr = BT_MESH_ADDR_ALL_NODES,
>                 .send_ttl = BT_MESH_TTL_DEFAULT,
>         };
>
>         bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP);
>         net_buf_simple_add_u8(msg, 1);
>
>         if (bt_mesh_model_send(&root_models[0], &ctx, msg, NULL, NULL)) {

A couple of things come to mind here:

Is root_models[0] really the model that's supposed to do the publishing?
It's often the Configuration Server Model, which would explain the error
you're getting. You didn't show the definition of your models array, so
I'm just guessing here.


You are right... Mistakenly specified the cfg_srv model. It is working fine now :)
 
Also, if this is really a formal publish message you're sending, you
should be using the bt_mesh_model_publish() API instead of
bt_mesh_model_send(). The latter is intended mainly for client model
messages as well as for the server's responses to those, and it doesn't
take into consideration things like the Model Publish Retransmit state
or that you're actually publishing using the configured publication
state (correct app key, destination address, TTL, etc).


Sure, will make use of it. Thanks for the clarification!

Regards,
Mani
 
Johan