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

Notification for Peripheral

Hi, I have to send data with notification from central to peripheral, because I need save some data in peripheral device. What I have to do ? I test it on Adnroid 4.4 (my central for testing). I use this functions

static uint32_t cccd_configure(uint16_t conn_handle, uint16_t cccd_handle, bool enable)
{
    uint8_t buf[BLE_CCCD_VALUE_LEN];
    
    buf[0] = enable ? BLE_GATT_HVX_NOTIFICATION : 0;
    buf[1] = 0;
    
    const ble_gattc_write_params_t write_params = {
        .write_op = BLE_GATT_OP_WRITE_REQ,
        .flags    = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE,
        .handle   = cccd_handle,
        .offset   = 0,
        .len      = sizeof(buf),
        .p_value  = buf
    };

    return sd_ble_gattc_write(conn_handle, &write_params);
}

uint32_t ble_deufol_notif_enable(ble_deufol_t * p_deufol)
{
    VERIFY_PARAM_NOT_NULL(p_deufol);

    if ( (p_deufol->conn_handle == BLE_CONN_HANDLE_INVALID)
       ||(p_deufol->common_handles.cccd_handle == BLE_GATT_HANDLE_INVALID)
       )
    {
        return NRF_ERROR_INVALID_STATE;
    }
    return cccd_configure(p_deufol->conn_handle,p_deufol->common_handles.cccd_handle, true);
}

after peripheral device is connected, but I get event BLE_GATTS_EVT_WRITE instead BLE_GATTC_EVT_HVX

I enable notification on Android

byte[] enableNotificationValue = new byte[BluetoothGattDescriptor.EnableNotificationValue.Count];
                            for (int i = 0; i < enableNotificationValue.Length; i++)
                            {
                                enableNotificationValue[i] = BluetoothGattDescriptor.EnableNotificationValue[i];
                            }
                            selectedGattDescriptor.SetValue(enableNotificationValue);
                            gatClient.WriteDescriptor(selectedGattDescriptor);
Parents Reply Children
No Data
Related