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

Using Simple message model.

Hi,

I have certain doubts regarding simple message model

1. Why simple_message_client_init or simple_message_server_init is never used? Don't we need this function to bind model to the element?

2. I am sending a message from client to server. Can I receive it from simple_message_server.c and vice versa?

3. I could not understand how the model's functions can be used and how the communication takes place.

  • Hi Arya,

    Mesh error 15 refers to NRF_ERROR_FORBIDDEN (see nrf_error.h). Do you have any idea where this error is called? What you can do is open the .map file in the build folder of your mesh example & find the location of 0x000267CD. It might be between two values.

    Most likely it is an error when you initialize the simple_model_client_init(). If it is, then the error says that "Multiple model instances per element is not allowed" (see declaration of function in simple_on_off_client.h). What this means is that you are initializing the simple_on_off_model & the simple_message_model on the same element (i.e. element indexes 2,3,4).

    I will double check about this internally & get back to you.

    Are you trying to initialize the custom client or the custom server model? The custom model should be initialized similar to the simple_on_off_client model (i.e. via the simple_on_off_client_init() function), like you have done above.

    Do you want four client models (e.g. one for each button) on the client board? 

    Kind Regards,

    Bjørn

  • Hi Bjørn,

    Sorry for the delay in reply. Error is coming from the function given below.

    static void models_init_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing and adding models1\n");
        uint32_t status = 0;
    
        for (uint32_t i = 0; i < CLIENT_MODEL_INSTANCE_COUNT; ++i)
        {
            m_clients[i].status_cb = client_status_cb;
            m_clients[i].timeout_cb = client_publish_timeout_cb;
            r_clients[i].status_cb = client_RSSI_status_cb;
            r_clients[i].timeout_cb = client_publish_timeout_cb;
            status = simple_on_off_client_init(&m_clients[i], i + 1);
            ERROR_CHECK(status);
            if(status == NRF_SUCCESS)
              {
                printf("NRF_SUCCESS\n");
              }
    
            ERROR_CHECK(access_model_subscription_list_alloc(m_clients[i].model_handle));
            status = simple_RSSI_client_init(&r_clients[i], i + 2);
            ERROR_CHECK(status);
            if(status == NRF_SUCCESS)
              {
                printf("NRF_SUCCESS\n");
              }
            ERROR_CHECK(access_model_subscription_list_alloc(r_clients[i].model_handle));
        }
    }
    

    error is in the 13th line of function given above. It executes once i.e when i = 0 and when i becomes one it gives an error at that point.

    Output is:

    NRF_SUCCESS
    NRF_SUCCESS
    <t:       7696>, app_error_weak.c,  105, Mesh error 15 at 0x000267CD

    I could not find the address 0x000267CD in .map file.

    As you said  the error is "Multiple model instances per element is not allowed".

    I have both custom server model as well as custom client model. Now I am trying to add custom client model. I am initializing my custom model like simple_on_off_client model. I have a function similar to that named simple_RSSI_client_init().

    Sorry I could not understand this question.

    "Do you want four client models (e.g. one for each button) on the client board?"

    I don't have a clear idea about element index.I still have the above error. I changed some parameters in function element_has_model_id but no change.

  • Hi Bjørn,

    It got resolved. I need only one switch for this model so I updated my function as this:

    static void models_init_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing and adding models1\n");
        uint32_t status = 0;
    
        for (uint32_t i = 0; i < CLIENT_MODEL_INSTANCE_COUNT; ++i)
        {
            m_clients[i].status_cb = client_status_cb;
            m_clients[i].timeout_cb = client_publish_timeout_cb;
            status = simple_on_off_client_init(&m_clients[i], i + 1);
            ERROR_CHECK(status);
            if(status == NRF_SUCCESS)
              {
                printf("NRF_SUCCESS\n");
              }
    
            ERROR_CHECK(access_model_subscription_list_alloc(m_clients[i].model_handle));
        }
        
            r_clients.status_cb = client_RSSI_status_cb;
            r_clients.timeout_cb = client_publish_timeout_cb;
            
            status = simple_RSSI_client_init(&r_clients, 0);
            ERROR_CHECK(status);
            if(status == NRF_SUCCESS)
              {
                printf("NRF_SUCCESS\n");
              }
            ERROR_CHECK(access_model_subscription_list_alloc(r_clients.model_handle));
    }
    

    changed this function too RSSI_server_index_get().

    uint32_t index = p_client - &r_clients;

    Also increased ACCESS_MODEL_COUNT. Now there is no error. Is this the correct way to do it? Assuming that this is the correct way to do it, how should I modify if I had more than one switch for this model?

  • Hi Bjørn,

    Now I don't get all those errors. But I can not send a string message. I added one button to send message using app timer in each one second using the the same function of simple message model, except that I am using my own API now. But it is returning NRF_ERROR_INVALID_PARAM. I know that this is because publication address allocation problem. How can I set my address properly? Or is it because model is not bound to appkey? The function is as shown below. 

    void address_new_set(uint16_t addr)                   //setting address for sending message
    {
      ERROR_CHECK(dsm_address_publish_add(addr, &m_central_handle));
      ERROR_CHECK(access_model_publish_address_set(r_server.model_handle, m_central_handle));
    }
    
    void send_new_message(void)                         //function for sending a simple message
    {
        uint32_t status=0;
        uint8_t buffer[5] = "hello";
        uint8_t length;
        uint16_t address;
        access_message_tx_t msg;
        length = sizeof(buffer); 
        
        if(length)
        {
          address = 0xCAFE; 
          address_new_set(address);
          SEGGER_RTT_printf(0,"Sending to group address 0x%04x\n", address);
          status= simple_RSSI_client_set_unreliable(r_clients.model_handle, &buffer, GROUP_MSG_REPEAT_COUNT);
    
          if(status == NRF_ERROR_INVALID_STATE ||
          status == NRF_ERROR_BUSY||
          status == NRF_ERROR_NO_MEM)
          {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Cannot send. Device is busy.\n");
            hal_led_blink_ms(LEDS_MASK, 50, 4);
          }
          else
          {
             ERROR_CHECK(status);
          }
        }
      
    }
    

    I took this function from simple message model and modified it.

  • Could you please upload the logging information from the client & server? You can run a debugging session using Segger Embedded Studio & just copy the logging information directly from the debug terminal.

Related