NRF Connect SDK: Bluetooth mesh, How to bind an existed appkey to a local model?

Dears all, 

When a bluetooth mesh node is done provisioning and added an appkey, I want to bind that appkey to  local models. 

I could not find any API for that.

Can you help me.

Best regards.

Parents
  • Dears,

    I just post this for any one that need.

    struct bt_mesh_comp bm_comp = {
        .cid = CONFIG_BT_COMPANY_ID,
        .elem = bm_elements,
        .elem_count = ARRAY_SIZE(bm_elements),
    };
    
    /*****/
    bt_mesh_init(&bm_prov, &bm_comp);

    void app_bm_local_config(void) {
        for (int e_idx=0; e_idx < bm_comp.elem_count; ++e_idx) {
            struct bt_mesh_elem *element = bm_comp.elem + e_idx;
            for (int m_idx = 0; m_idx < element->model_count; ++m_idx) {
                struct bt_mesh_model *model = element->models + m_idx;
                if (model->id == BT_MESH_MODEL_ID_CFG_SRV || model->id == BT_MESH_MODEL_ID_CFG_CLI || 
                    model->id == BT_MESH_MODEL_ID_HEALTH_SRV || model->id == BT_MESH_MODEL_ID_HEALTH_CLI) 
                    continue;
                if (model->keys[0] == 0xFFFF) {
                    model->keys[0] = 0; /*Appkey index is 0*/
                }
                for (int k_idx=0; k_idx < CONFIG_BT_MESH_MODEL_KEY_COUNT; k_idx++) LREP_RAW("%d ", model->keys[k_idx]);
                if (model->pub) {
                    if (model->pub->addr == 0) {
                        model->pub->addr = 0xC000; /*Publish to group address 0xC000*/
                    }
                }
            }
        }
    }

    It worked with me. But It cannot save the configuration so every time the SOC is restart, the app_bm_local_config() must be call

    Best regards.

Reply
  • Dears,

    I just post this for any one that need.

    struct bt_mesh_comp bm_comp = {
        .cid = CONFIG_BT_COMPANY_ID,
        .elem = bm_elements,
        .elem_count = ARRAY_SIZE(bm_elements),
    };
    
    /*****/
    bt_mesh_init(&bm_prov, &bm_comp);

    void app_bm_local_config(void) {
        for (int e_idx=0; e_idx < bm_comp.elem_count; ++e_idx) {
            struct bt_mesh_elem *element = bm_comp.elem + e_idx;
            for (int m_idx = 0; m_idx < element->model_count; ++m_idx) {
                struct bt_mesh_model *model = element->models + m_idx;
                if (model->id == BT_MESH_MODEL_ID_CFG_SRV || model->id == BT_MESH_MODEL_ID_CFG_CLI || 
                    model->id == BT_MESH_MODEL_ID_HEALTH_SRV || model->id == BT_MESH_MODEL_ID_HEALTH_CLI) 
                    continue;
                if (model->keys[0] == 0xFFFF) {
                    model->keys[0] = 0; /*Appkey index is 0*/
                }
                for (int k_idx=0; k_idx < CONFIG_BT_MESH_MODEL_KEY_COUNT; k_idx++) LREP_RAW("%d ", model->keys[k_idx]);
                if (model->pub) {
                    if (model->pub->addr == 0) {
                        model->pub->addr = 0xC000; /*Publish to group address 0xC000*/
                    }
                }
            }
        }
    }

    It worked with me. But It cannot save the configuration so every time the SOC is restart, the app_bm_local_config() must be call

    Best regards.

Children
No Data
Related