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

Use GET to retrieve the value of 3 variables - Mesh SDK 2.0.1

Hi,

I'm using a modified version of the light_switch example to control a RGB led on Mesh SDK 2.0.1.

I already managed to control the led by using 3 variables for each color (red, green and blue). So, from the "SET" I'm done (except for the status_reply).

Now I want to be able to use the "GET" to know the actual value of the 3 variables on the server side.

I modified the reply_status function as follow:

static void reply_status(const simple_on_off_server_t * p_server,
                         const access_message_rx_t * p_message,
                         uint8_t current_red_dt_cycle, uint8_t current_green_dt_cycle, uint8_t current_blue_dt_cycle)
{
    simple_on_off_msg_status_t status;
    //status.present_on_off = present_on_off ? 1 : 0;
    status.current_red_dt_cycle = current_red_dt_cycle;
    status.current_green_dt_cycle = current_green_dt_cycle;
    status.current_blue_dt_cycle = current_blue_dt_cycle;
    access_message_tx_t reply;
    reply.opcode.opcode = SIMPLE_ON_OFF_OPCODE_STATUS;
    reply.opcode.company_id = SIMPLE_ON_OFF_COMPANY_ID;
    reply.p_buffer = (const uint8_t *) &status;
    reply.length = sizeof(status);
    reply.force_segmented = false;
    reply.transmic_size = NRF_MESH_TRANSMIC_SIZE_DEFAULT;

    (void) access_model_reply(p_server->model_handle, p_message, &reply);
}

Accordingly I modified the simple_on_off_msg_status_t struct in simple_on_off_common.h:

typedef struct __attribute((packed))
{
    uint8_t current_red_dt_cycle;
    uint8_t current_green_dt_cycle; /**< Current state. */
    uint8_t current_blue_dt_cycle;
} simple_on_off_msg_status_t;

Now, my problem is that I couldn't figure out how to pass the 3 variable values when calling the reply_status function on the handle_get_cb, and also how the get_cb works...



Another question is how will I return the 3 values on the main.c when executing the on_off_server_get_cb function?

BR,
Paulo Zacarias

  • Hello,

    I am sorry, I have been trying to set up a separate module in the Mesh light_switch example, but I have not yet finished. I have some problem with the provisioning.

     

    Regarding returning 3 parameters, that is not possible in C. You have to put them in a struct and return a pointer to them. Exactly how to send this out on the Mesh network, I am not yet sure. This is what I am looking into. I will get back to you if I figure something out.

     

    I assume that you modified the on_off_model, and didn't add another model with the RGB values, is that correct?

    I assume that you haven't modified the access_model_reply() function? 

     

    Can you check what access_model_reply() returns?

     

    try:

    uint32_t err_code = access_model_reply();

    ERROR_CHECK(err_code);

    And set a breakpoint on the ERROR_CHECK(err_code); line and see what it returns.

     

    Best regards,

    Edvin

  • Hi Edvin,

    Thank you for your reply.

    Regarding your questions:

    1. I assume that you modified the on_off_model, and didn't add another model with the RGB values, is that correct?

    Yes, so far I just modified the on_off_model, I haven't added any other model.

    2. I assume that you haven't modified the access_model_reply() function?

    No, I haven't modified the access_model_reply() function.

    3. Can you check what access_model_reply() returns?

    I haven't been able even to build the solution. I'm still struggling with the reply_status function and the get_cb on the handle_get_cb...

    I tried to use pointers to return 3 parameters in the main.cb, as follow:

    static bool on_off_server_get_cb(const simple_on_off_server_t * p_server, uint8_t * current_red_dt_cycle, uint8_t * current_green_dt_cycle, uint8_t * current_blue_dt_cycle)
    {
        //return hal_led_pin_get(LED_PIN_NUMBER);
        * current_red_dt_cycle = red_duty_cycle;
        * current_green_dt_cycle = green_duty_cycle;
        * current_blue_dt_cycle = blue_duty_cycle;
    }

    But I still don't know how to modify the get_cb to accept 3 parameters (I can't even find where get_cb is defined):



    So, until I figure out how to solve this, I can't run it and check what access_model_reply() returns.

    Any directions on how to proceed? Thank you in advance!

    BR,

    Paulo Zacarias

  • Ok. I understand.

     

    You should change your reply_status, and the status of the different LEDs should be stored in the reply and status.

     

    You must change your model's status from simple_on_off_msg_status_t, which currently only holds one uint8_t present_on_off, to hold one uint8_t for each.

    Then change the reply_status:

    status.red = red;

    status.green = green;

    status.blue = blue;

     

    Then you need to change the callback function, which is currently named the on_off_server_get_cb().

    The get_cb() function call is a typedef, declared on line 63 in simple_on_off_server.h:

    typedef bool (*simple_on_off_get_cb_t)(const simple_on_off_server_t * p_self);

     

    If you want to add arguments to this, add it after (const simple_on_off_server_t * p_self, uint8_t * value 1 ...)

    You also need to create the variables current_red/green/blue_dt_cycle; variables. These can be stored in your simple_on_off_server.c/h files.

    These will be the ones that you use in reply_status:

    status.red = current_red_dt_cycle;

    status.green = current_green_dt_cycle;

    status.blue = current_blue_dt_cycle;

     

    Note that this is only changing the pointers handed to the on_off_server_get_cb(), and not returning them. You need to change the on_off_server_get_cb to be a void function (or simply return true or false, and ignore the return value).

     

     

    I am sorry if this was a bit messy. But to sum up, my suggestion is the following:

    in main.c: on_off_server_get_cb: use the implementation that you attached now, and add return true; at the end, or change static bool to void. 

    in simple_on_off_common.h:  change:

    /** Message format for the Simple OnOff Status message. */
    typedef struct __attribute((packed))
    {
        uint8_t present_on_off; /**< Current state. */
    } simple_on_off_msg_status_t;
    
    to
    
    /** Message format for the Simple OnOff Status message. */
    typedef struct __attribute((packed))
    {
        uint8_t current_red; /**< Current state. */
        uint8_t current_green; /**< Current state. */
        uint8_t current_blue; /**< Current state. */
    } simple_on_off_msg_status_t;

     

    in simple_on_off_server.h: on line 63: change:

    typedef bool (*simple_on_off_get_cb_t)(const simple_on_off_server_t * p_self);

    to

    typedef bool (*simple_on_off_get_cb_t)(const simple_on_off_server_t * p_self, uint8_t * current_red_dt_cycle, ...); (the same as your on_off_server_get_cb() function) The values from these pointers must be accessible from reply_status() in simple_on_off_server.c.

     

    in simple_on_off_server.c: change status,present_on_off = present_on_off ? 1 : 0;

    to

    status.red = red;

    status.green = green;

    status.blue = blue;

    where red green and blue are the values in the pointers that you change in get_cb.

     

    BR,

    Edvin

Related