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,

    I would not refer to this simple message model, as it is using an outdated mesh sdk. I would rather take a look at the light switch example in the newest mesh sdk v2.1.1. Follow the testing guidelines there and run a debug session or have an rtt viewer open in each of the three boards (provisioner, client, server) & take a look at how the light switch example works. 

    Also, make sure to take a look at the configuration model in the provisioner (config_client.c & config_client.h), as well as config_server.c & config_server.h in the client example. I would also recommend taking a look at this documentation, as well as the simple OnOff Model documentation.

  • Hi Bjørn,

    I am working in mesh 2.0.1. I have added this simple message model into my light switch example. What I actually want is to send a string from client to server. That is done through simple message model. But it is not handling messages as it is in simple on off model. I have gone through light switch model as well as the documentation on adding new models. I think I should merge these two models (Light switch and simple message model). Or I should remove on off model and add a new model which can send a string and can handle messages. Would that be possible?

  • What about if you create a new model based off of the simple on off model instead? If you take a look at the light switch client example, you can see that when a user presses button 1 on the dev kit, the client sends a unicast message to the first provisioned server using the simple_on_off_client_set() function. This function first makes sure that the parameter pointer p_client & the status_cb pointer are not null. Then, a check is done to make sure the client is not in an invalid state. 

    It's this struct that is interesting for us:

    /** Simple OnOff Client state structure. */
    struct __simple_on_off_client
    {
        /** Model handle assigned to the client. */
        access_model_handle_t model_handle;
        /** Status callback called after status received from server. */
        simple_on_off_status_cb_t status_cb;
        /** Timeout callback called after acknowledged message sending times out */
        simple_on_off_timeout_cb_t timeout_cb;
        /** Internal client state. */
        struct
        {
            bool reliable_transfer_active; /**< Variable used to determine if a transfer is currently active. */
            simple_on_off_msg_set_t data;  /**< Variable reflecting the data stored in the server. */
        } state;
    };

    The simple_on_off_msg_set struct contains the on_off state (i.e. whether the server light should be on or off).

    The simple_on_off_client_set() function then calls send_reliable_message(), which will then send the data via the access_model_reliable_publish() call on the access layer of the mesh stack. 

    What if you try to create a new model based on the simple on off model & then update the simple_on_off_msg_set_t struct to send a string message instead of uint8_t on_off?

    I would also recommend making a copy of each of the three light switch examples (provisioner, client, server) & modify those. This way, if you were to make a mistake & the mesh network does not work anymore, you can refer back on the working light switch example. Hope that helps!

  • Hi Bjørn,

    Thank you for that suggestion. I have created a new model based on that. How can I init that new model? I tried adding the new model in 'models_init_cb()', along with simple on off model. I added a snippet given below.

    static void models_init_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing and adding models\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;
            ERROR_CHECK(simple_on_off_client_init(&m_clients[i], i + 1));
            ERROR_CHECK(access_model_subscription_list_alloc(m_clients[i].model_handle));
        }
        for (uint32_t j = 0; j < CLIENT_MODEL_INSTANCE_COUNT; ++j)
        {
            r_clients[j].status_cb = new_client_status_cb;
            r_clients[j].timeout_cb = client_publish_timeout_cb;
            ERROR_CHECK(simple_model_client_init(&r_clients[j], j + 1));
            ERROR_CHECK(access_model_subscription_list_alloc(r_clients[i].model_handle));
        }
    
    }
    

    But it is returning error. when I removed the simple on off part, it is returning NRF_SUCCESS. Should I add it in a different function similar to 'models_init_cb'? If then how should I add the new model to the structure 'mesh_stack_init_params_t'?  Like this?

    static void mesh_init(void)
    {
        mesh_stack_init_params_t init_params =
        {
            .core.irq_priority       = NRF_MESH_IRQ_PRIORITY_LOWEST,
            .core.lfclksrc           = DEV_BOARD_LF_CLK_CFG,
            .core.p_uuid             = m_client_node_uuid,
            .models.models_init_cb   = models_init_cb,
            .models.models_init_cb   = models_init_cb2,
            .models.config_server_cb = config_server_evt_cb
        };
        ERROR_CHECK(mesh_stack_init(&init_params, &m_device_provisioned));
    }
    

    Where the 'models_init_cb2' is a function which initializes only the new client model? Is it like I can not add a new model apart from simple on off model with out removing it?

  • Hi Bjørn,

    I tried this way.

    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 = new_client_status_cb;
            r_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));
            status = simple_model_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));
        }
    }

    But it is returning this error

    app_error_weak.c,  105, Mesh error 15 at 0x000267CD. Can you help me with this?

Related