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

Receiving simple message mesh

Hi, 

I followed this thread (Link) to implement a simple message model on the light switch example from nRF SDK for Mesh v1.0.1. I created a "send_simple_message" function with all the given code that i call in a function called when a button is pushed on the client.

It seems the message is sent since i receive a "0" status after "access_model_publish". From the server, the led still change its state when i push the button; but i don't know how to read the message (and how to receive it).

Do i have to use the "simple_message_init" function and the others functions defined in the model, how to and when ?
Has somebody implemented the simple message model and could help me?

Thanks.

Parents
  • Hi,

    If you take a look at the mesh light switch example in the mesh sdk v1.0.1 inside the main.c file, you can see the nrf_mesh_node_config() function call at the bottom of the int main(void) function. Going to the definition of the nrf_mesh_node_config() file, the access layer gets initialized inside the access_init() function. Inside the access_init() function, there is a line: 

    m_evt_handler.evt_cb = mesh_evt_cb;

    Going to the definition of mesh_evt_cb, you can see that whenever the NRF_MESH_EVT_MESSAGE_RECEIVED event occurs, the mesh_msg_handle() function gets called. It seems that this mesh_msg_handle() function, which is defined in access.c, handles the incoming mesh messages on the server side. This is defined similarly on the client side too (can be checked by looking at the client mesh example). The mesh simple model is given in the link you provided, so that should work correctly.

    What exactly is not working in the link you provided. Is it the provisioning or is it something else?

     

     

  • The provisioning works since i am able to turn on the server's LEDs from the client.

    On the client, I just included the simple message model and SEGGER_RTT.h in my project and created a function "send_my_message" that i call when the Button 4 is pressed.
    I also created an instance of dsm_handle_t : "static dsm_handle_t m_central_handle;" and modified few lines of the given

    code to make it compile:

    void send_my_message (void) 
    {
        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)
                    { 
                      msg.opcode.opcode = simple_message_OPCODE_SEND;
                      msg.opcode.company_id = 0x0059; // Nordic's company ID
          
                      msg.p_buffer = (const uint8_t *) &buffer[0];
                      msg.length =length;
                      address = 0xCAFE;
                      address_set(address);
                      SEGGER_RTT_printf(0,"Sending to group address 0x%04x\n", address);
                      status= access_model_publish(m_clients[3].model_handle, &msg);
                      __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Status : %u \n", status);
    
                      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);
                       }
                    }
    }


    On the server, i just included the "simple_message_server". Am I supposed to do something else (init...) ? 

    The status i get after "access_model_publish" is 0 so i suppose my message has been sent but i do not receive anything on the server.

    Thanks for the help!

  • Like I mentioned in my other post, you'll want to include the same code that you implemented on the client side also on the server side. This is to ensure that you can communicate from client to server, but also the other way around. Just read & implement everything after: Inside the message_server main.c file:

  • hi,

    how would you define address_set function? like this?

    void address_set(uint16_t addr)
    {
    ERROR_CHECK(dsm_address_publish_add(addr, &m_central_handle));
    ERROR_CHECK(access_model_publish_address_set(m_server.model_handle, m_central_handle));
    }

    if yes then how do u define m_server?? how do you create an instance?

  • Hi norin,

    It looks like that I am meeting the same trouble as yours,i can not find the definition of m_sever,Have you already resolved this problem?could you please share me with any methods to this?

    thank you very much.

  • Hi Bjorn,

    I created a simple_message modle,but when I pressed a button to send my message,I got a status of 7 in the function :access_model_publish(m_clients[0].model_handle, &msg);so I think it is fail to send the message,the error reason from access.c feil:

    if ((p_rx_message == NULL &&
    (m_model_pool[handle].model_info.publish_appkey_handle == DSM_HANDLE_INVALID ||
    m_model_pool[handle].model_info.publish_address_handle == DSM_HANDLE_INVALID)) ||
    !is_valid_opcode(p_tx_message->opcode))
    {
    *p_status = NRF_ERROR_INVALID_PARAM;
    }

    I can't understand the parameter in "if" statements.Can you help me for some advance?

    Thanks in advance.

Reply
  • Hi Bjorn,

    I created a simple_message modle,but when I pressed a button to send my message,I got a status of 7 in the function :access_model_publish(m_clients[0].model_handle, &msg);so I think it is fail to send the message,the error reason from access.c feil:

    if ((p_rx_message == NULL &&
    (m_model_pool[handle].model_info.publish_appkey_handle == DSM_HANDLE_INVALID ||
    m_model_pool[handle].model_info.publish_address_handle == DSM_HANDLE_INVALID)) ||
    !is_valid_opcode(p_tx_message->opcode))
    {
    *p_status = NRF_ERROR_INVALID_PARAM;
    }

    I can't understand the parameter in "if" statements.Can you help me for some advance?

    Thanks in advance.

Children
  • The if statement first checks if the p_rx_message pointer does not point to an address in memory & then checks to make sure the appkey & address publish handles provided by the Device State Manager are valid. Lastly, there is a check to make sure the operation code (opcode) is valid or not. You could print out the values of each of the variables before the if statement to check which of the variables lead to the error.

Related