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

Sending Config Relay Set message through Config Client

Hello,

I'm working on Mesh SDK 2.1.1 and I'm trying to send a Relay Set message through Configuration Client.

I have changed the code of models_init_cb() function inside the main.c to initialize the Config Client Model:

static config_client_event_cb_t config_client_cb

(...)

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 = client_status_cb;
        m_clients[i].timeout_cb = client_publish_timeout_cb;
        ERROR_CHECK(simple_on_off_client_init(&m_clients[i], i + 1));
        ERROR_CHECK(access_model_subscription_list_alloc(m_clients[i].model_handle));
    }
    
    ERROR_CHECK(config_client_init(&config_client_cb));
}

The model seems to initialize properly, as I can see it after provisioning the node using the Android App and I'm able to bind an application key and to set a publication address.

Then I use the config_client_relay_set() function to set the relay configuration:

status = config_client_relay_set(CONFIG_RELAY_STATE_SUPPORTED_DISABLED, 7, 31);


However, I get the status NRF_ERROR_INVALID_PARAM.

After looking at what happens after executing the relay set function, I realized that this status comes from the function check_tx_params() in access.c more precisely from this Boolean check:

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

Looking at what is inside the m_model_pool, I can see that for the Config Client Model, the values of both publish_appkey_handle and publish_address_handle correspond to DSM_HANDLE_INVALID.

So, what could be the cause?

Is it something missing from the Model initialization? Or how should I configure the application key and the publish address?

If I understood correctly the Configuration Client should work within the node it self, right?

Should I then define the publish address as the first node element, i.e., the address of the element that contains the Configuration Server, Configuration Client and Health Server?

And what about the application key?

  • I will try to provide you with an answer by the upcoming monday/tuesday

  • Are you sure you have set the application key and the publish address correctly. I was able to add the config client model, and successfully execute the config_client_relay_set(..). The following steps was taken:

    • Started with the light_switch_proxy_client example
    • Added config_client(..) init to models_init_cb():

    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 = client_status_cb;
            m_clients[i].timeout_cb = client_publish_timeout_cb;
            ERROR_CHECK(simple_on_off_client_init(&m_clients[i], i + 1));
            ERROR_CHECK(access_model_subscription_list_alloc(m_clients[i].model_handle));
        }
        ERROR_CHECK(config_client_init(app_config_client_event_cb));
    }

    • Added an extra model in ACCESS_MODEL_COUNT:

    #define ACCESS_MODEL_COUNT (1 + /* Configuration server */  \
                                1 + /* Health server */  \
                                2 + /* Simple OnOff client (2 groups) */ \
                                2 + /* Simple OnOff client (2 unicast) */ \
                                1 /* Config client model, not included initially */)
    

    • Added config_client_relay_set(..) under button press 3

    static void button_event_handler(uint32_t button_number)
    {
    .
    .
    .
        case 2:
                   __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "config_client_relay_set\n");
                  status = config_client_relay_set(CONFIG_RELAY_STATE_SUPPORTED_DISABLED, 7, 31);
    
                  break;

    • Opened the nRF Mesh app, scanned and found the device (nRF5x Mesh Switch), clicked on it
    • Pressing button 2 now resulted in NRF_ERROR_INVALID_PARAM
    • Provisioned it, and added both an application key and a publish address for the Configuration Client model
    • Pressing button 2 (running config_client_relay_set(..) ) worked fine

    I am not sure why it didn't work for you, maybe you are able to figure out why by looking at the steps above.

    Best regards, Simon

  • Hi,

    Thanks for your reply.

    My steps are similar to yours, so I tried to Provision the node again. No success, same NRF_ERROR_INVALID_PARAM error.

    So my questions are:

    1. How do you declare the app_config_client_event_cb? I have in the following way:

    static config_client_event_cb_t config_client_cb = CONFIG_CLIENT_EVENT_TYPE_MSG;

    I had to declare it that way because if I don't assign the type CONFIG_CLIENT_EVENT_TYPE_MSG, I get the error 14, NRF_ERROR_NULL when initializing the model.

    2. After provisioning, how do you configure the node? Do you bind the App key 1 that is shown by default?

    And what publish address did you set? In my case should I use 0x0001 that corresponds to the element address of the Configuration model?

     



    If my mistake is not in one of those steps, then I don't know where else should I look for. Everything else is as you shown.


    The experiment you did was with Mesh SDK 2.1.1 as well, right?

    BR,

    Paulo

  • Question 1:

    When calling config_client_init(..) you need to provide it with a callback function of the following type

    typedef void (*config_client_event_cb_t)(config_client_event_type_t event_type, const config_client_event_t * p_event, uint16_t length);

    Thus, a function with three arguments:

    • event_type
    • p_event (Pointer to event data, may be NULL.)
    • length

    When config client events happens, this function will be used, and processing may be done based on the arguments. Below shows the callback I used (borrowed from the light switch provisioner example):

    static void app_config_client_event_cb(config_client_event_type_t event_type, const config_client_event_t * p_event, uint16_t length)
    {
        /* USER_NOTE: Do additional processing of config client events here if required */
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Config client event\n");
    
        /* Pass events to the node setup helper module for further processing */
        //node_setup_config_client_event_process(event_type, p_event, length);
    }

    Try setting config_client_cb to a callback function instead of an event type.

    Question 2:

    • Yes, I used App key 1
    • I used the same publish address

    The only difference I can see between our approaches is the one mentioned in question 1. I am using the same sdk (Mesh SDK 2.1.1).

    Best regards, Simon

Related