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

  • 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;
    }

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

  • Hi,

    Just to clarify, you want two client models on the same node?

    I suspect that not enough elements have been added to the node so when you try to initiate the model in the inputted element index it will return invalid element index. Can you check that you also have added the correct amount of elements to the node?

    Note that if you want multiple instances of the same model, these instances cannot be in the same element and a separate element is needed for each new instance of the same model.

  • DeaMttrinh:

    It is right.
    we hope add two client models into sever model to implement a control model on the same node.
    After adding enough elements to the node in the "nrf_mesh_conf_app.h", we can the "run mesh_init()" function successfully.
    The "nrf_mesh_conf_app.h" was modified as the following.
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //#define ACCESS_MODEL_COUNT (/* Element 0:                                       */ \
    //                            1 + /* Config Server                                */ \
    //                            1 + /* Health Server                                */ \
    //                            1 + /* Generic OnOff Server                         */ \
    //                            1 + /* Default Transition Time Server               */ \
    //                            1 + /* Scene Server                                 */ \
    //                            1   /* Scene Setup Server (extends Scene Server)    */)

    #if 1
    //2021.0916  .....add Generic OnOff client model ......
    #define ACCESS_MODEL_COUNT (/* Element 0:                                       */ \
                                1 + /* Config Server                                */ \
                                1 + /* Health Server                                */ \
                                1 + /* Generic OnOff Server                         */ \
                                1 + /* Default Transition Time Server               */ \
                                1 + /* Scene Server                                 */ \
                                1 +  /* Scene Setup Server (extends Scene Server)   */ \
                                2   /* Generic OnOff client (2 groups) */)

    #endif
    /**
     * The number of elements in the application.
     *
     * @warning If the application is to support _multiple instances_ of the _same_ model, these instances
     * cannot be in the same element and a separate element is needed for each new instance of the same model.
     */
    //2021.0916 ......update element count .....
    //#define ACCESS_ELEMENT_COUNT (1)
    #define ACCESS_ELEMENT_COUNT (3)

    //#define ACCESS_ELEMENT_COUNT (1 + CLIENT_MODEL_INSTANCE_COUNT) /* One element per Generic OnOff client instance */
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    Then we ran the "BLE Mesh APP" to add a node in the cell phone and found the elements of "Generic_on_off_client" had been add into the node as below.
    Best Regards,
    Sheng-Hua
Related