This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Mesh SDK light switch example combining client and server

Hi All:

We are using nRF52840 SDK with BLE Mesh sdk5.0 to develop bluetooth mesh and we can use light_sw_client to control the LED1 state on the light_sw_sever via BLE Mesh APP and   nRF52840_DK.

Now we hope to integrated the ight_sw_client and  light_sw_sever to implement bi-direction data transfer between two nRF52840_DK.

The integrated light_sw client and server can be compliled successfully,but executing the mesh_stack_init function has a error message( Mesh error 5 at 0x00027B49) from the function of "ERROR_CHECK(generic_onoff_client_init(&m_clients[i], i + 1))".

How to debug the issue? Thanks a lot.

/***************************************************************************

static void mesh_init(void)
{
/* Initialize the application storage for models */
model_config_file_init();

mesh_stack_init_params_t init_params =Post
{
.core.irq_priority = NRF_MESH_IRQ_PRIORITY_LOWEST,
.core.lfclksrc = DEV_BOARD_LF_CLK_CFG,
.core.p_uuid = NULL,
.models.models_init_cb = models_init_cb,
.models.config_server_cb = config_server_evt_cb
};

uint32_t status = mesh_stack_init(&init_params, &m_device_provisioned);

*************************************************************************************/

static void models_init_cb(void)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing and adding models\n");
app_model_init();

// ..... adding client models ....
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing and adding client models\n");

for (uint32_t i = 0; i < CLIENT_MODEL_INSTANCE_COUNT; ++i)
{
m_clients[i].settings.p_callbacks = &client_cbs;
m_clients[i].settings.timeout = 0;
m_clients[i].settings.force_segmented = APP_FORCE_SEGMENTATION;
m_clients[i].settings.transmic_size = APP_MIC_SIZE;

ERROR_CHECK(generic_onoff_client_init(&m_clients[i], i + 1));
}

Best Regards,

Sheng-Hua

Parents
  • Hi,

    Getting Mesh error 5 (NRF_ERROR_NOT_FOUND) from generic_onoff_client_init() function means invalid access element index. Can you check that the element index is correct?

  • Dear Mttrinh:

    Thanks your support.

    We integrated the following codes of light_sw_client to light_sw_sever in models_init_cb function.

    In debug procedure, we found that the element_index is 1 and 2 in the "generic_onoff_client_init"; and the element_index is 1 in "generic_onoff_server_init".

    Best Regards,

    Sheng-Hua

    // ..... adding client models ....///////////////////////////////////////////////////////////////////////////////////////////////////
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing and adding client models\n");

    for (uint32_t i = 0; i < CLIENT_MODEL_INSTANCE_COUNT; ++i)
    {
    m_clients[i].settings.p_callbacks = &client_cbs;
    m_clients[i].settings.timeout = 0;
    m_clients[i].settings.force_segmented = APP_FORCE_SEGMENTATION;
    m_clients[i].settings.transmic_size = APP_MIC_SIZE;

    ERROR_CHECK(generic_onoff_client_init(&m_clients[i], i + 1));

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /***********************************************************************************************

    uint32_t generic_onoff_client_init(generic_onoff_client_t * p_client, uint8_t element_index)
    {
    if (p_client == NULL ||
    p_client->settings.p_callbacks == NULL ||
    p_client->settings.p_callbacks->onoff_status_cb == NULL ||
    p_client->settings.p_callbacks->periodic_publish_cb == NULL)
    {
    return NRF_ERROR_NULL;
    }

    if (p_client->settings.timeout == 0)
    {
    p_client->settings.timeout= MODEL_ACKNOWLEDGED_TRANSACTION_TIMEOUT;
    }

    access_model_add_params_t add_params =
    {
    .model_id = ACCESS_MODEL_SIG(GENERIC_ONOFF_CLIENT_MODEL_ID),
    .element_index = element_index,
    .p_opcode_handlers = &m_opcode_handlers[0],
    .opcode_count = ARRAY_SIZE(m_opcode_handlers),
    .p_args = p_client,
    .publish_timeout_cb = p_client->settings.p_callbacks->periodic_publish_cb
    };

    uint32_t status = access_model_add(&add_params, &p_client->model_handle);

    if (status == NRF_SUCCESS)
    {
    status = access_model_subscription_list_alloc(p_client->model_handle);
    }

    return status;
    }

    ************************************************************************************************/

     /**********************************************************************************************/

    uint32_t app_onoff_init(app_onoff_server_t * p_app, uint8_t element_index)
    {
    uint32_t status = NRF_ERROR_INTERNAL;

    if (p_app == NULL)
    {
    return NRF_ERROR_NULL;
    }

    p_app->server.settings.p_callbacks = &m_onoff_srv_cbs;
    if ( (p_app->onoff_get_cb == NULL) ||
    ( (p_app->onoff_set_cb == NULL) &&
    (p_app->onoff_transition_cb == NULL) ) )
    {
    return NRF_ERROR_NULL;
    }

    status = generic_onoff_server_init(&p_app->server, element_index);
    if (status != NRF_SUCCESS)
    {
    return status;
    }

    /* Set the default state.
    */
    status = generic_onoff_mc_open(&p_app->server.state_handle);
    if (status != NRF_SUCCESS)
    {
    return status;
    }

    ****************************************************************************************************/

Reply
  • Dear Mttrinh:

    Thanks your support.

    We integrated the following codes of light_sw_client to light_sw_sever in models_init_cb function.

    In debug procedure, we found that the element_index is 1 and 2 in the "generic_onoff_client_init"; and the element_index is 1 in "generic_onoff_server_init".

    Best Regards,

    Sheng-Hua

    // ..... adding client models ....///////////////////////////////////////////////////////////////////////////////////////////////////
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing and adding client models\n");

    for (uint32_t i = 0; i < CLIENT_MODEL_INSTANCE_COUNT; ++i)
    {
    m_clients[i].settings.p_callbacks = &client_cbs;
    m_clients[i].settings.timeout = 0;
    m_clients[i].settings.force_segmented = APP_FORCE_SEGMENTATION;
    m_clients[i].settings.transmic_size = APP_MIC_SIZE;

    ERROR_CHECK(generic_onoff_client_init(&m_clients[i], i + 1));

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /***********************************************************************************************

    uint32_t generic_onoff_client_init(generic_onoff_client_t * p_client, uint8_t element_index)
    {
    if (p_client == NULL ||
    p_client->settings.p_callbacks == NULL ||
    p_client->settings.p_callbacks->onoff_status_cb == NULL ||
    p_client->settings.p_callbacks->periodic_publish_cb == NULL)
    {
    return NRF_ERROR_NULL;
    }

    if (p_client->settings.timeout == 0)
    {
    p_client->settings.timeout= MODEL_ACKNOWLEDGED_TRANSACTION_TIMEOUT;
    }

    access_model_add_params_t add_params =
    {
    .model_id = ACCESS_MODEL_SIG(GENERIC_ONOFF_CLIENT_MODEL_ID),
    .element_index = element_index,
    .p_opcode_handlers = &m_opcode_handlers[0],
    .opcode_count = ARRAY_SIZE(m_opcode_handlers),
    .p_args = p_client,
    .publish_timeout_cb = p_client->settings.p_callbacks->periodic_publish_cb
    };

    uint32_t status = access_model_add(&add_params, &p_client->model_handle);

    if (status == NRF_SUCCESS)
    {
    status = access_model_subscription_list_alloc(p_client->model_handle);
    }

    return status;
    }

    ************************************************************************************************/

     /**********************************************************************************************/

    uint32_t app_onoff_init(app_onoff_server_t * p_app, uint8_t element_index)
    {
    uint32_t status = NRF_ERROR_INTERNAL;

    if (p_app == NULL)
    {
    return NRF_ERROR_NULL;
    }

    p_app->server.settings.p_callbacks = &m_onoff_srv_cbs;
    if ( (p_app->onoff_get_cb == NULL) ||
    ( (p_app->onoff_set_cb == NULL) &&
    (p_app->onoff_transition_cb == NULL) ) )
    {
    return NRF_ERROR_NULL;
    }

    status = generic_onoff_server_init(&p_app->server, element_index);
    if (status != NRF_SUCCESS)
    {
    return status;
    }

    /* Set the default state.
    */
    status = generic_onoff_mc_open(&p_app->server.state_handle);
    if (status != NRF_SUCCESS)
    {
    return status;
    }

    ****************************************************************************************************/

Children
No Data
Related