Heelo, i'm trying to use a nordic nrf5340 as a provisioner for the remaining network however i'm getting an error on sending the app-key to the un-provisioned node (I'm using the mesh provisioner example as a guide).
Both the devices exchange the correct information until the app-key add step.
Provisioner log: (The status code is different everytime)
Bluetooth initialized Mesh initialized Loading stored settings Provision Complete Provision Complete Using stored CDB Using stored settings UART initialized New device: 2ef3540c530a4faf80eb000000000002 Provisioning device Method: No Auth Node added Check unconfigured Configuring node 0x0002... Status: 206 Err -11 Failed to add app-key (err -11 status 206)
I've narrow it down to the return on this function from "cfg_cli.c":
int bt_mesh_cfg_app_key_add(uint16_t net_idx, uint16_t addr, uint16_t key_net_idx,
uint16_t key_app_idx, const uint8_t app_key[16],
uint8_t *status)
{
BT_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_ADD, 19);
struct bt_mesh_msg_ctx ctx = {
.net_idx = net_idx,
.app_idx = BT_MESH_KEY_DEV_REMOTE,
.addr = addr,
.send_ttl = BT_MESH_TTL_DEFAULT,
};
struct app_key_param param = {
.status = status,
.net_idx = key_net_idx,
.app_idx = key_app_idx,
};
int err;
err = cli_prepare(¶m, OP_APP_KEY_STATUS, addr);
if (err) {
return err;
}
bt_mesh_model_msg_init(&msg, OP_APP_KEY_ADD);
key_idx_pack(&msg, key_net_idx, key_app_idx);
net_buf_simple_add_mem(&msg, app_key, 16);
err = bt_mesh_model_send(cli->model, &ctx, &msg, NULL, NULL);
if (err) {
BT_ERR("model_send() failed (err %d)", err);
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
return err;
}
if (!status) {
bt_mesh_msg_ack_ctx_clear(&cli->ack_ctx);
return 0;
}
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
}
The error happens because the timeout of the ack message, i've ben trying to narrow it down even further but no success, does anyone know what it could be?
EDIT (PLEASE TAKE INTO CONSIDERATION)
From what i understand the problem is in the await acknowledged message in the cfg_cli.c script like this
In the line 40 of the function above presented
return bt_mesh_msg_ack_ctx_wait(&cli->ack_ctx, K_MSEC(msg_timeout));
The script does the correct thing and blocks the device for "msg_timeout" ms and afterwards it checks if the semaphore "&ack->sem" (Saying the message got replied) however this is where the problem exists. It get's timedout and clears the ack field from the config client before receiving the message itself like this
Configuring node 0x0003... **The expected response is saved into config client fields** Prepared Response OpCode: 0x8003 addr : 0x0003 Sending message **The await function times out** Failed to add app-key (err -11 status 0) **Received a message with the expected OpCode** OpCode 0x8003 received **The config client field was cleared due to time out** Prepared response OpCode: 0x0000 addr : 0x0000 **Message is always rejected by match** Response received ------------------- OpCode : 0x0000 -- 0x8003 isUnicast : true addr : 0 -- 3 ------------------- Message not the expected