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

"sd_ble_gattc_write" and "BLE_GATTC_EVT_WRITE_RSP"

I have a question about "sd_ble_gattc_write" and "BLE_GATTC_EVT_WRITE_RSP".

1) If "BLE_GATTC_EVT_WRITE_RSP" occurs, can you guarantee that the data has been written to the characteristic reliably?
2) Is "BLE_GATTC_EVT_WRITE_RSP" correct in recognition occurring at the connection interval timing after executing "sd_ble_gattc_write"?
3) Is there a case where "BLE_GATTC_EVT_WRITE_RSP" does not occur?
4) In that case, is it necessary to execute "sd_ble_gattc_write" again?

Thanking you in advance.

Parents
  • Hi,

    BLE is a reliable protocol which means that every packet that is sent needs to acknowledged by the receiver. This is done in the lower layers of the stack and is not related to BLE_GATT_EVT_RSP which is an event related to the application layer.

    1. You can therefore guarantee that the peer devices has received your packet if BLE_GATTC_EVT_WRITE_RSP is generated after a WRITE, but not necessarily guarantee that the characteristics has been written to as it depends on the application at the peer device. The application will return an error response if didn't allow the characteristic to be written and success otherwise. 
    2. This question is not clear for me. 
    3. No, but it can be either success or an error.
    4. See previous.
    5. No, this is related to the lower layers. 
    6. See this post.

    Best regards

    Jared

  • Thank you for answering.
    Let me ask you some more questions.

    3) How do I judge success or errors?
    6) Please tell me how to set the number of retransmissions.
        Also, at what timing is retransmission done?
        Is it done every connection interval?

  • Hi, 

    1. You can determine if the characteristic has been  successfully written to by waiting for the BLE_GATTC_EVT_WRITE_RSP event and see if the status of the event is a BLE_GATT_STATUS_SUCCESS. If the WRITE is not permitted a error code will be received with the BLE_GATTC_EVT_WRITE_RSP event. I've included sample code from the ble event handler in nrf_ble_ots_c file that shows how to check if the WRITE is success or not:
    2. You can't set the number of re transmission, the device will continuously try to re transmit a packet until the connection times out. However, you can decide the connection timeout, most of our examples use the definition CONN_SUP_TIMEOUT to set the time out. See this post and this post

    regards 

    Jared 

    void nrf_ble_ots_c_on_ble_evt(ble_evt_t const * const p_ble_evt,
                                  void            * p_context)
    {
        nrf_ble_ots_c_t * p_ots_c;
        p_ots_c = (nrf_ble_ots_c_t*) p_context;
    
        VERIFY_MODULE_INITIALIZED_VOID();
        VERIFY_PARAM_NOT_NULL_VOID(p_ots_c);
        VERIFY_PARAM_NOT_NULL_VOID(p_ble_evt);
    
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GAP_EVT_DISCONNECTED:
                on_disconnect(p_ots_c, p_ble_evt);
                break;
    
            case BLE_GATTC_EVT_READ_RSP:
                on_read_rsp(p_ots_c, p_ble_evt);
                break;
    
            case BLE_GATTC_EVT_WRITE_RSP:
                if ((p_ble_evt->evt.gattc_evt.error_handle != BLE_GATT_HANDLE_INVALID)
                    && (p_ble_evt->evt.gattc_evt.error_handle ==
                        p_ots_c->service.object_action_cp_char.handle_value))
                {
                    if (p_ble_evt->evt.gattc_evt.gatt_status == BLE_GATT_STATUS_ATTERR_CPS_CCCD_CONFIG_ERROR)
                    {
                        NRF_LOG_INFO("write to OACP failed, CCCD improperly configured, enable indications on OACP and try again");
                    }
                    else
                    {
                        NRF_LOG_INFO("BLE_GATTC_EVT_WRITE_RSP error handle: %x error response %x\r\n",
                                     p_ble_evt->evt.gattc_evt.error_handle,
                                     p_ble_evt->evt.gattc_evt.gatt_status);
                    }
                }
                break;
    
            default:
                break;
        }
        ots_c_l2cap_on_ble_evt(p_ots_c, p_ble_evt);
        ots_c_oacp_on_ble_evt(p_ots_c, p_ble_evt);
    }

Reply Children
No Data
Related