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

Send string in a Mesh. With nRF52DK

Hello:

I have to nRF52DK boards and I am able to run the ligth_switch example, but the thing that I want to do is send a message, "hello" from one node to other. I saw the example in the Q&A, here but the example talks about the Mesh SDK v1.0.0. and I have the nrf5SDKforMeshv310src examples.

In the code I can't figure how to send a string.

Could you give me some clues to do it?

Thank you.

  • Hi Guillermo

    Due to the Easter holiday you will have to expect a delay in replies, sorry for the inconvenience!

    We do not have any examples of this for Mesh 3.1. But I suggest you have a look at or Getting started guide on how to creale your own models in mesh. Alternatively, it is possible to use the nrf_mesh_packet_send() API for access to the lower layers in the spec, found here on our GitHub.

    Best regards,

    Simon

  • Hi Simonr:

    Don't worry it is Easter Holiday in my country too.

    I will check and I give you some feedback as soon as I try it.

  • Hello, did you have some success on this? I have the same problem too.
    I was trying to implement a Library called 'simple message' but it only works with the old Mesh SDK 1.0
    If anyone could help me showing me some tutorial for sending and receiving strings in mesh

  • hello ,Did you do it? I had the same problem

  • Hello Sir  I got the messages to be sent and received over the light_switch example by modifying the type of every data variable to uint8_t * (you can notice that every data variables have the same bool type).

    After that, I force the message to be unsegmented, that means that the message will only support like 9 characters, so, it's good to be aware about that.

    then, I used a new opcode for receiving and sending string data over there.

    These are the functions to be changed over the Generic OnOff client code on the generic_onoff_client.c

    static uint8_t message_set_packet_create(generic_onoff_set_msg_pkt_t *p_set, const generic_onoff_set_params_t * p_params,
                                          const model_transition_t * p_transition)
    {
            p_set->on_off= p_params->on_off;
            p_set->tid = p_params->tid;
    
            if (p_transition != NULL)
            {
                p_set->transition_time = model_transition_time_encode(p_transition->transition_time_ms);
                p_set->delay = model_delay_encode(p_transition->delay_ms);
                return GENERIC_ONOFF_SET_MAXLEN; //I put a value of 9 over there
            }
            else
            {
                return GENERIC_ONOFF_SET_MINLEN;
            }
    }
    
    uint32_t generic_onoff_client_set(generic_onoff_client_t * p_client, const generic_onoff_set_params_t * p_params,
                                      const model_transition_t * p_transition)
    {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "%x\n", p_client->model_handle);
    
        if (p_client == NULL || p_params == NULL)
        {
            return NRF_ERROR_NULL;
        }
        if (p_transition != NULL &&
            (p_transition->transition_time_ms > TRANSITION_TIME_MAX_MS ||
             p_transition->delay_ms > DELAY_TIME_MAX_MS))
        {
            return NRF_ERROR_INVALID_PARAM;
        }
    
        if (access_reliable_model_is_free(p_client->model_handle))
        {
            uint8_t server_msg_length = message_set_packet_create(&p_client->msg_pkt.set, p_params, p_transition);
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "p_params.onoff: %s\n", p_client->msg_pkt.set.on_off);
            message_create(p_client, GENERIC_ONOFF_OPCODE_SET, p_client->msg_pkt.set.on_off,
                           server_msg_length, &p_client->access_message.message);
            reliable_context_create(p_client, GENERIC_ONOFF_OPCODE_STATUS, &p_client->access_message);
            return access_model_reliable_publish(&p_client->access_message);
        }
        else
        {
            return NRF_ERROR_BUSY;
        }
    }

    This code is part of the Generic OnOff Server's code and should be modified.

    //This one is the new function that I use with the operational code
    static void handle_send_status(access_model_handle_t model_handle, const access_message_rx_t * p_rx_msg, void * p_args){
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "A/C state: %s\n", p_rx_msg->p_data);
    }
    
    static const access_opcode_handler_t m_opcode_handlers[] =
    {
        {ACCESS_OPCODE_SIG(GENERIC_ONOFF_OPCODE_SET), handle_set},
        {ACCESS_OPCODE_SIG(GENERIC_ONOFF_OPCODE_SET_UNACKNOWLEDGED), handle_set},
        {ACCESS_OPCODE_SIG(GENERIC_ONOFF_OPCODE_GET), handle_get},
        {ACCESS_OPCODE_SIG(OPCODE_SEND_STATUS), handle_send_status}, //I added this one
    };
    
    

Related