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

Mesh for more than one models

Hi, 

I am using nRF52832 to design a mesh system,  starting with light.

Everything is fine, and development is reaching the end.  

Before today, I use only one model,  modified on Simple_On_Off, with multi states to control light from cellphone , everything works fine. Now I am try to add two more models,

say total three models,defined as:

static simple_on_off_client_t     m_clients[CLIENT_MODEL_INSTANCE_COUNT];
static light_lightness_client_t     L_lightness_clients[CLIENT_MODEL_INSTANCE_COUNT];
static light_hsl_client_t               L_hsl_clients[CLIENT_MODEL_INSTANCE_COUNT];

Increased MODEL INSTANCE COUNT IN "light_switch_example_common"

/** Number of On-Off client models on the Switch Node */
#define CLIENT_MODEL_INSTANCE_COUNT (6)

/** Number of group address being used in this example */
#define GROUP_ADDR_COUNT (4)

Add and initiate models here:

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

for (uint32_t i = 0; i < CLIENT_MODEL_INSTANCE_COUNT; ++i)
{
m_clients[i].status_cb = on_off_client_status_cb;
m_clients[i].timeout_cb = on_off_client_publish_timeout_cb;
L_lightness_clients[i].status_cb = lightness_client_status_cb;
L_lightness_clients[i].timeout_cb = lightness_client_publish_timeout_cb;
L_hsl_clients[i].status_cb = hsl_client_status_cb;
L_hsl_clients[i].timeout_cb = hsl_client_publish_timeout_cb;

ERROR_CHECK(simple_on_off_client_init(&m_clients[i], i + 1));
ERROR_CHECK(light_lightness_client_init(&L_lightness_clients[i], i + 1));
ERROR_CHECK(light_hsl_client_init(&L_hsl_clients[i], i + 1));

ERROR_CHECK(access_model_subscription_list_alloc(m_clients[i].model_handle));
ERROR_CHECK(access_model_subscription_list_alloc(L_lightness_clients[i].model_handle));
ERROR_CHECK(access_model_subscription_list_alloc(L_hsl_clients[i].model_handle));
}
}

compiled fine,  but  when debug, Mesh Error 4   comes from model add.

<t: 0>, main.c, 419, ----- BLE Mesh Light Switch Client Demo -----
<t: 535>, main.c, 320, Initializing and adding models
<t: 541>, app_error_weak.c, 105, Mesh error 4 at 0x000267B9 (G:\Light_Bulb_Project\mesh_bulb_211\examples\light_switch\proxy_client\src\main.c:333)

I really do not understand which step(s) is missed ,  

Please help, very urgent.

Brent

Parents
  • Hi Brent,

    Which mesh sdk version are you currently using? Have you already taken look at the documentation provided here?

    Kind Regards,

    Bjørn

  • Hi, Bjørn

    I upgraded mesh sdk to 2.1.1, and  followed to documentation for add new models,  you can see the steps in message.

    Thanks

    Brent

  • Hi Brent,

    Error 4 refers to NRF_ERROR_NO_MEM (see nrf_error.h). You should also take a look at line 333 in main.c to see by which function the error is called.

    You can also look where 0x000267B9 in the map file which can be located in the build folder here: nrf5_SDK_for_Mesh_v2.1.1_src\examples\light_switch\proxy_client\build\light_switch_proxy_client_nrf52832_xxAA_s132_6.0.0_Debug\. Open up the .map file extension & look for where the 0x000267B9 is located.

    Did you remember to initialize the model to allocate, initialize & bind the model to the element like described in the documentation. I can see that you call the light_lightness_client_init() function. Would you mind uploading the light_lightness_client_init() function code? Did you call access_model_add() like in the config_server_init() function in config_server.c of the light switch proxy client example?

    Also, did you define the opcode handlers like described in the documentation? If I were you, I would take a look at how the configuration server, health server or simple on off server is initialized & do something similar for the other two models you want to add.

    Kind Regards,

    Bjørn

  • Hi, Bjørn

    Thanks for your help, finally I find the reason.

    There is  ACCESS_MODEL_COUNT in "nrf_mesh_config_app" . It is actually controlls the memory use on model add.

    After Adjust the model qty,  there is no problem anymore.

    ---------------------------------------------------------------------------------------------------------

    Here I met another problem, please help.

    I am using proxy.c to establish an data link with smartphone via mesh_GATT.

    What I am doing is like this:

    For TX ,

    it is actually a service notification

    1. I created a function to use proxy_connection,  I understand, only one connection permited.

    static void send_data_to_smartphone(proxy_connection_t * p_connection)
    {

    __LOG(LOG_SRC_BEARER, LOG_LEVEL_INFO, "START TX\n");

    proxy_enable();
    if (packet_alloc(p_connection, MESH_GATT_PDU_TYPE_NETWORK_PDU, SEAT_BELT_PACKET_SIZE, NRF_MESH_SERVICE_BORDER_TOKEN) ==
    NRF_SUCCESS)

    {
    memcpy(p_connection->p_alloc_packet, seat_belt_data.tx_data, sizeof(seat_belt_data.tx_data));
    // memset(seat_belt_data.tx_data,0xFF,SEAT_BELT_PACKET_SIZE);
    }

    packet_send(p_connection);

    }

    2. I  called this function  in

    " static void gatt_evt_handler(const mesh_gatt_evt_t * p_evt, void * p_context)"

    at  position:

      case MESH_GATT_EVT_TYPE_TX_READY:
    __LOG(LOG_SRC_BEARER, LOG_LEVEL_INFO, "TX ready\n");

    send_data_to_smartphone(p_connection);
    beacon_cycle_send(p_connection);
    break;

    3. Smartphone side: start nRF Connect

    Result:   1)  from smartphone I can see data keep coming ,but it is not my data;

                    2)  in debug process, 
    __LOG(LOG_SRC_BEARER, LOG_LEVEL_INFO, "START TX\n");

         do not show up?

    for RX

    I follow  rx_handle function , 

    case MESH_GATT_EVT_TYPE_RX:
    __LOG(LOG_SRC_BEARER, LOG_LEVEL_INFO, "RX\n");
    rx_handle(p_connection,
    p_evt->params.rx.pdu_type,
    p_evt->params.rx.p_data,
    p_evt->params.rx.length);

    to file "network .c", inside

    uint32_t network_packet_in(const uint8_t * p_packet, uint32_t net_packet_len, const nrf_mesh_rx_metadata_t * p_rx_metadata)

    I put :


    #if GATT_PROXY
    if(p_rx_metadata->source==NRF_MESH_RX_SOURCE_GATT)
    {
    __LOG(LOG_SRC_BEARER, LOG_LEVEL_INFO, "RX2_Start\n");
    memcpy(seat_belt_data.rx_data,&net_decrypted_packet,sizeof(net_decrypted_packet));
    }

    try to memcopy the pocket arrive from  mesh GATT.

    Result. 

    1. smartphone side:  when I try to write data, the connection terminated immediately,.

    2. in debug process,  I can not see any reaction , even log info.

    Please help how to move at this point.

    Thanks a lot.

    Brent 

Reply
  • Hi, Bjørn

    Thanks for your help, finally I find the reason.

    There is  ACCESS_MODEL_COUNT in "nrf_mesh_config_app" . It is actually controlls the memory use on model add.

    After Adjust the model qty,  there is no problem anymore.

    ---------------------------------------------------------------------------------------------------------

    Here I met another problem, please help.

    I am using proxy.c to establish an data link with smartphone via mesh_GATT.

    What I am doing is like this:

    For TX ,

    it is actually a service notification

    1. I created a function to use proxy_connection,  I understand, only one connection permited.

    static void send_data_to_smartphone(proxy_connection_t * p_connection)
    {

    __LOG(LOG_SRC_BEARER, LOG_LEVEL_INFO, "START TX\n");

    proxy_enable();
    if (packet_alloc(p_connection, MESH_GATT_PDU_TYPE_NETWORK_PDU, SEAT_BELT_PACKET_SIZE, NRF_MESH_SERVICE_BORDER_TOKEN) ==
    NRF_SUCCESS)

    {
    memcpy(p_connection->p_alloc_packet, seat_belt_data.tx_data, sizeof(seat_belt_data.tx_data));
    // memset(seat_belt_data.tx_data,0xFF,SEAT_BELT_PACKET_SIZE);
    }

    packet_send(p_connection);

    }

    2. I  called this function  in

    " static void gatt_evt_handler(const mesh_gatt_evt_t * p_evt, void * p_context)"

    at  position:

      case MESH_GATT_EVT_TYPE_TX_READY:
    __LOG(LOG_SRC_BEARER, LOG_LEVEL_INFO, "TX ready\n");

    send_data_to_smartphone(p_connection);
    beacon_cycle_send(p_connection);
    break;

    3. Smartphone side: start nRF Connect

    Result:   1)  from smartphone I can see data keep coming ,but it is not my data;

                    2)  in debug process, 
    __LOG(LOG_SRC_BEARER, LOG_LEVEL_INFO, "START TX\n");

         do not show up?

    for RX

    I follow  rx_handle function , 

    case MESH_GATT_EVT_TYPE_RX:
    __LOG(LOG_SRC_BEARER, LOG_LEVEL_INFO, "RX\n");
    rx_handle(p_connection,
    p_evt->params.rx.pdu_type,
    p_evt->params.rx.p_data,
    p_evt->params.rx.length);

    to file "network .c", inside

    uint32_t network_packet_in(const uint8_t * p_packet, uint32_t net_packet_len, const nrf_mesh_rx_metadata_t * p_rx_metadata)

    I put :


    #if GATT_PROXY
    if(p_rx_metadata->source==NRF_MESH_RX_SOURCE_GATT)
    {
    __LOG(LOG_SRC_BEARER, LOG_LEVEL_INFO, "RX2_Start\n");
    memcpy(seat_belt_data.rx_data,&net_decrypted_packet,sizeof(net_decrypted_packet));
    }

    try to memcopy the pocket arrive from  mesh GATT.

    Result. 

    1. smartphone side:  when I try to write data, the connection terminated immediately,.

    2. in debug process,  I can not see any reaction , even log info.

    Please help how to move at this point.

    Thanks a lot.

    Brent 

Children
Related