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

Callback of client two times when i only use function: generic_onoff_client_get

Hi,

i'm current working on example light switch, when i use function   generic_onoff_client_get(); in client to get status from server, callback function app_generic_onoff_client_status_cb(); response two times. i see in the function generic_onoff_client_get(); had two opcode: OPCODE_GET and OPCODE_STATUS. But in file generic_onoff_client.c only process OPCODE_STATUS via status_handle(); function, i wonder how can i receive response only 1 time.

Thanks you

  • I have tested this myself with the light switch example from mesh sdk v3.1.0. The only changes I made were to make the button 4 on the client send a generic_onoff_client_get() message instead of a set message, i.e. my button event handler function likes like this now:

    static void button_event_handler(uint32_t button_number)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Button %u pressed\n", button_number);
    
        uint32_t status = NRF_SUCCESS;
        generic_onoff_set_params_t set_params;
        model_transition_t transition_params;
        static uint8_t tid = 0;
    
        /* Button 1: On, Button 2: Off, Client[0]
         * Button 2: On, Button 3: Off, Client[1]
         */
    
        switch(button_number)
        {
            case 0:
            case 2:
                set_params.on_off = APP_STATE_ON;
                break;
    
            case 1:
            //case 3:
                set_params.on_off = APP_STATE_OFF;
                break;
        }
    
        set_params.tid = tid++;
        transition_params.delay_ms = APP_CONFIG_ONOFF_DELAY_MS;
        transition_params.transition_time_ms = APP_CONFIG_ONOFF_TRANSITION_TIME_MS;
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Sending msg: ONOFF SET %d\n", set_params.on_off);
    
        switch (button_number)
        {
            case 0:
            case 1:
                /* Demonstrate acknowledged transaction, using 1st client model instance */
                /* In this examples, users will not be blocked if the model is busy */
                (void)access_model_reliable_cancel(m_clients[0].model_handle);
                status = generic_onoff_client_set(&m_clients[0], &set_params, &transition_params);
                hal_led_pin_set(BSP_LED_0, set_params.on_off);
                break;
    
            case 2:
            //case 3:
                /* Demonstrate un-acknowledged transaction, using 2nd client model instance */
                status = generic_onoff_client_set_unack(&m_clients[1], &set_params,
                                                        &transition_params, APP_UNACK_MSG_REPEAT_COUNT);
                hal_led_pin_set(BSP_LED_1, set_params.on_off);
                break;
           case 3:
                status = generic_onoff_client_get(&m_clients[0]);
                break;
        }
    
        switch (status)
        {
            case NRF_SUCCESS:
                break;
    
            case NRF_ERROR_NO_MEM:
            case NRF_ERROR_BUSY:
            case NRF_ERROR_INVALID_STATE:
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Client %u cannot send\n", button_number);
                hal_led_blink_ms(LEDS_MASK, LED_BLINK_SHORT_INTERVAL_MS, LED_BLINK_CNT_NO_REPLY);
                break;
    
            case NRF_ERROR_INVALID_PARAM:
                /* Publication not enabled for this client. One (or more) of the following is wrong:
                 * - An application key is missing, or there is no application key bound to the model
                 * - The client does not have its publication state set
                 *
                 * It is the provisioner that adds an application key, binds it to the model and sets
                 * the model's publication state.
                 */
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Publication not configured for client %u\n", button_number);
                break;
    
            default:
                ERROR_CHECK(status);
                break;
        }
    }

    Then, using nRF Mesh, I made the first client subscribe to the unicast address where the location of the generic on off server model was located (in my case 0x0004). The weird thing I noticed is that whenever I send a get message from the client to the server, sometimes I receive one status message from the server, but other times I receive 2 status message. See the log below for details. Even though the log says I am sending set messages, this is not the case. I am sending a get message each time (see button_event_handler code above for details). Do you also notice this?

    <t:    8615977>, main.c,  227, Sending msg: ONOFF SET 58
    <t:    8790801>, access.c,  268, p_evt->dst.value: 0x0002
    <t:    8790804>, main.c,  147, Acknowledged transfer success.
    <t:    8790807>, main.c,  178, OnOff server: 0x0004, Present OnOff: 0
    <t:    8798665>, access.c,  268, p_evt->dst.value: 0x0002
    <t:    8798668>, main.c,  178, OnOff server: 0x0004, Present OnOff: 0
    <t:    8992239>, main.c,  200, Button 3 pressed
    <t:    8992241>, main.c,  227, Sending msg: ONOFF SET 220
    <t:    9175167>, access.c,  268, p_evt->dst.value: 0x0002
    <t:    9175171>, main.c,  147, Acknowledged transfer success.
    <t:    9175173>, main.c,  178, OnOff server: 0x0004, Present OnOff: 0
    <t:    9323896>, main.c,  200, Button 3 pressed
    <t:    9323898>, main.c,  227, Sending msg: ONOFF SET 123
    <t:    9324740>, access.c,  268, p_evt->dst.value: 0x0002
    <t:    9324743>, main.c,  147, Acknowledged transfer success.
    <t:    9324745>, main.c,  178, OnOff server: 0x0004, Present OnOff: 0
    <t:    9450010>, main.c,  200, Button 3 pressed
    <t:    9450012>, main.c,  227, Sending msg: ONOFF SET 22
    <t:    9459277>, access.c,  268, p_evt->dst.value: 0x0002
    <t:    9459280>, main.c,  147, Acknowledged transfer success.
    <t:    9459283>, main.c,  178, OnOff server: 0x0004, Present OnOff: 0
    <t:    9561260>, main.c,  200, Button 3 pressed
    <t:    9561263>, main.c,  227, Sending msg: ONOFF SET 111
    <t:    9743729>, access.c,  268, p_evt->dst.value: 0x0002
    <t:    9743733>, main.c,  147, Acknowledged transfer success.
    <t:    9743735>, main.c,  178, OnOff server: 0x0004, Present OnOff: 0
    

    Kind Regards,

    Bjørn Kvaale

  • Yes, i had noticed it. I totally agree with you about get message, i test again and mostly i receive 1 status message but sometime i receive 2 status message. I think it fine but i wonder if i can ask you another question about status response, when i transfer data from client to server by function use generic_onoff_client_set_unack();. I always receive 2 message status. How can i fix it? I only need response status message only 1 one time, it make me confuse so much.

    Thanks you

  • Are you sure you are using generic_onoff_client_set_unack()? You should not receive a status message if the message is unacknowledged. If this is the case, let me know & I will test a bit myself.

  • yes, i alaways receive two message status, can you help me test again and find out the way of this issue ? 

Related