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

Error codes for sd_ble_gatts_hvx

I am trying to send just random dummy data to my android app. 
First of all, I am not expecting or need the confirmation, so I should be using the notification and not indication, because indication requires the confirmation, right?

There are 2 scenarios that are happening. I start sending data without setting notification on Android and I seem to be sending data but getting error 3401. If I got it right this means exactly that, that the other side has no notification enabled?

The other situation is when I enable notification on app side but after 5-6 messages it get error code 13, which means that something timed out?

I am a little bit lost on what I am doing wrong, because my app receives all of those messages. How and what would be correct way to handle this?

Parents
  • Hi,

    You have to check the error message and act accordingly, If you use a for loop you will most likely get NRF_ERROR_RESOURCES, once the buffers are used. Then you have to exit the for loop, and wait for BLE_GATTS_EVT_HVN_TX_COMPLETE before you start calling sd_ble_gatts_hvx again.

    See flow chart here: GATTS Handle Value Notification

  • Yes, I am getting NRF_ERROR_RESOURCES, forgot hex to decimal conversion. I thought it is NRF_ERROR_TIMEOUT.

    Lets say I have something as simple as this. What would be correct way to handle that?

    for(int i = 0; i <= 20; i++){
        uint8_t data[] = {5, 0, 0, 0};
        err_code = ble_mds_on_tx_change(m_conn_handle, &m_mds, data);
        
        NRF_LOG_INFO("err_code: %x", err_code);
    
        if (err_code != NRF_SUCCESS &&
            err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
            err_code != NRF_ERROR_INVALID_STATE &&
            err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING) {
            APP_ERROR_CHECK(err_code);
        }
    }
    
    


    EDIT:
    I am actually now waiting for BLE_GATTS_EVT_HVN_TX_COMPLETE to send new data. However with this the time goes up to 100 ms between data. My goal is to test fastest I can send it, in theory I should be able to do so with 7.5 ms? Would scenario where I would just send data and forget about it be possible?
    Also with error I am getting would it be possible to just clear buffer and continue?

Reply
  • Yes, I am getting NRF_ERROR_RESOURCES, forgot hex to decimal conversion. I thought it is NRF_ERROR_TIMEOUT.

    Lets say I have something as simple as this. What would be correct way to handle that?

    for(int i = 0; i <= 20; i++){
        uint8_t data[] = {5, 0, 0, 0};
        err_code = ble_mds_on_tx_change(m_conn_handle, &m_mds, data);
        
        NRF_LOG_INFO("err_code: %x", err_code);
    
        if (err_code != NRF_SUCCESS &&
            err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
            err_code != NRF_ERROR_INVALID_STATE &&
            err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING) {
            APP_ERROR_CHECK(err_code);
        }
    }
    
    


    EDIT:
    I am actually now waiting for BLE_GATTS_EVT_HVN_TX_COMPLETE to send new data. However with this the time goes up to 100 ms between data. My goal is to test fastest I can send it, in theory I should be able to do so with 7.5 ms? Would scenario where I would just send data and forget about it be possible?
    Also with error I am getting would it be possible to just clear buffer and continue?

Children
Related