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

BLE_NUS_C_EVT_NUS_TX_EVT has handle of 0xffff

I have following problem:

I am using a multilink NUS Central. With one peripheral connection everything works fine. But when make a second connection I sometimes get an error when I try to send data back in received event.

In ble_nus_c_evt_handler event with event type BLE_NUS_C_EVT_NUS_TX_EVT the p_ble_nus_c sometimes has an invalid connection handle (0xFFFF).

If I try to send data back I get following warning: <warning> ble_nus_c: Connection handle invalid.

How is this possible? I am assigning the handles with  ble_nus_c_handles_assign on discovery complete.

Does anyone know about this issue?

  • Did you try to implement something similar as in the previous snippet? You need to look for the place that forwards the BLE_NUS_C_EVT_NUS_TX_EVT, and add the connection handle in this event.

    look in ble_nus_c.c, and search for BLE_NUS_C_EVT_NUS_TX_EVT. 

    Add this line:

    ble_nus_c_evt.conn_handle = p_ble_evt->evt.gattc_evt.conn_handle;

    before:

    p_ble_nus_c->evt_handler(p_ble_nus_c, &ble_nus_c_evt);

  • Please check out this ticket with a similar question. I attached a project in this ticket that works in SDK15.2.0. If you need to use SDK15.0.0, then you must do some debugging.

    Can you please set a breakpoint in on_hvx() in the ble_nus_c.c file? What is the  conn_handle if you check:

    ble_nus_c_evt.conn_handle = p_ble_evt->evt.gattc_evt.conn_handle; ?

    NB: gattc_evt, not gap_evt, which I wrote in an earlier answer (corrected now).

    Best regards,

    Edvin

  • static void on_hvx(ble_nus_c_t * p_ble_nus_c, ble_evt_t const * p_ble_evt)
    {
        // HVX can only occur from client sending.
        if (   (p_ble_nus_c->handles.nus_tx_handle != BLE_GATT_HANDLE_INVALID)
            && (p_ble_evt->evt.gattc_evt.params.hvx.handle == p_ble_nus_c->handles.nus_tx_handle)
            && (p_ble_nus_c->evt_handler != NULL))
        {
            ble_nus_c_evt_t ble_nus_c_evt;
    
            ble_nus_c_evt.evt_type = BLE_NUS_C_EVT_NUS_TX_EVT;
            ble_nus_c_evt.p_data   = (uint8_t *)p_ble_evt->evt.gattc_evt.params.hvx.data;
            ble_nus_c_evt.data_len = p_ble_evt->evt.gattc_evt.params.hvx.len;
    			
    				ble_nus_c_evt.conn_handle = p_ble_evt->evt.gattc_evt.conn_handle;
    			
    			
            p_ble_nus_c->evt_handler(p_ble_nus_c, &ble_nus_c_evt);
            NRF_LOG_DEBUG("Client sending data.");
        }
    }
    

    i have modify the code but it do not work! 

  • Edvin said:

    Can you please set a breakpoint in on_hvx() in the ble_nus_c.c file? What is the  conn_handle if you check:

    ble_nus_c_evt.conn_handle = p_ble_evt->evt.gattc_evt.conn_handle; ?

Related