This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

BLE_GATTS_EVT_HVN_TX_COMPLETE event does not works on NUS for multi-role device

Hi,

In a multi-role central-peripheral code for a nRF52840-DK based device, I have to send a buffer acting as a peripheral. I use the ble_nus_data_send function sent as a trigger in the BLE_GAP_EVT_CONNECTED (into the ble_evt_handler function). So, I send the first data packet once the connection as peripheral has been established.

The rest of the buffer was expected to be sent using the BLE_GATTS_EVT_HVN_TX_COMPLETE event into the ble_evt_handler function. However, the event does not never occurs.

In fact, when I execute ble_nus_data_send the first time, it returns a NRF_ERROR_INVALID_STATE because it detects a condition ike !p_client->is_notification_enabled.

I have tried to clone the NUS configuration (as a peripheral) from the ble_app_uart example, working using the nRF5_SDK_17.1.0_ddde560. And including the sdk_config.h file configuration.

What should I setup to enable the BLE_GATTS_EVT_HVN_TX_COMPLETE event? Should I use another event?

Thank you very much in advance.

Best Regards,

Joel

Parents
  • Hi Joel,

    I cannot think of any situation where you would not get a BLE_GATTS_EVT_HVN_TX_COMPLETE notification as long as the notification/indication is successfully sent. If it is, it should always arrive, though you might not get the same number of BLE_GATTS_EVT_HVN_TX_COMPLETE events as you send notifications, as the same event can cover more than one notification (in that case, the count field informs you how many notifications has been sent).

    Could it be that you are for instance filtering on the wrong connection handle, and therefor do not see the events? This is just a guess, though.

    If you don't make progress, perhaps you can share your event handling code here so that I can see if I spot anything?

Reply
  • Hi Joel,

    I cannot think of any situation where you would not get a BLE_GATTS_EVT_HVN_TX_COMPLETE notification as long as the notification/indication is successfully sent. If it is, it should always arrive, though you might not get the same number of BLE_GATTS_EVT_HVN_TX_COMPLETE events as you send notifications, as the same event can cover more than one notification (in that case, the count field informs you how many notifications has been sent).

    Could it be that you are for instance filtering on the wrong connection handle, and therefor do not see the events? This is just a guess, though.

    If you don't make progress, perhaps you can share your event handling code here so that I can see if I spot anything?

Children
  • Hi Einar,

    The definition is:

    BLE_NUS_DEF(m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT);

    The initialization is:

        ble_nus_init_t   nus_init;

        memset(&nus_init, 0, sizeof(nus_init));
        nus_init.data_handler = nus_data_handler;
        err_code = ble_nus_init(&m_nus, &nus_init);

    In the ble_evt_handler. In the BLE_GAP_EVT_CONNECTED event it discriminates if it works a central device or like a peripheral. In this second case it executes the next:

                    m_per_con_handle = p_gap_evt->conn_handle;
                    NRF_LOG_INFO("Peripheral connection 0x%x established.", m_per_con_handle);    
                    
                    app_timer_start(m_post_message_delay_timer_id, APP_TIMER_TICKS(2000), 0);
                    
                    app_timer_stop(m_adv_led_blink_timer_id);
                    
                    bsp_board_led_on(PERIPHERAL_ADV_CON_LED);
                    punter_buffer_accelerometre= 0;
                    num_rebuts_buffer_accelerometre= 128003;
                    send_data_ble_accel();

    Into the function send_data_ble_accel function the code executes

                   err_code = ble_nus_data_send(&m_nus, data_buf, &length, m_per_con_handle);

    If I debug this function in this stage I can see that the notification is not enabled.

    As a peer I'm using a second nRF52840-DK board running the ble_central_and_peripheral\experimental\ble_app_att_mtu_throughput example. Here I select the buttin 4. This board establish the connection as a central device and recognizes the other board.

    Regards,

    Joel

  • Hi Joel,

    Ah, I misunderstood the question. I thought notifications actually were sent, but you did not see the BLE_GATTS_EVT_HVN_TX_COMPLETE  event. Based on what you write now I see that the notifications are not enabled and so they are not (and cannot be) sent.

    So, the client (central in this case) needs to enable the notifications by writing to the CCCD. Once done, you can send notifications. So that is the first thing you must get working.

  • Hi,

    I'm trying to use Nordic examples as a entral device. AndI thought that in the ATT_MTU example working as central the client notification were enabled. Are they not? What should I do to enable them?

    Or do you think should I use the ble_app_uart_c example? How should I enable the notifications there?

    Thank you in advance.

    Regards,

    Joel

  • Hi Joel,

    I am not exactly sure which changes you have done and how, but the way this works is that the Bluetooth connection is established, the GATT client (which is typically the central here) does service discovery, and after that it can enable notifications on characteristics that support it and it want notifications on. That seems to not be done here. If you refer to the NUS central example, you will see that it does enable notifications, and you must do the same (search for "ble_nus_c_tx_notif_enable" in examples/ble_central/ble_app_uart_c/main.c). 

  • Hi Einar,

    I will make a double check. I will come back tomorrow.

    By the way, I will have to connect it to an iPhone app in the end. This app will work as the central that has to enable then the notifications. Do you see anything special should I do from the device side?

    Regards,

    Joel

Related