# Amebaz2 - BLE CCCD Default

**URL:** <https://forum.amebaiot.com/t/amebaz2-ble-cccd-default/1365>\
**Category:** USB\
**Tags:** rtl872xd\
**Created:** [July 23, 2022, 6:25am UTC](https://forum.amebaiot.com/t/amebaz2-ble-cccd-default/1365 "2022-07-23T06:25:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wanglemao](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/wanglemao/32/1079_2.png) [@wanglemao](https://forum.amebaiot.com/u/wanglemao)\
**Post date:** [July 23, 2022, 6:25am UTC](https://forum.amebaiot.com/t/amebaz2-ble-cccd-default/1365/1 "2022-07-23T06:25:10Z")

</div>

我声明了一个notify的cccd，初始值为：DNA\_BLE\_GATT\_CLIENT\_CHAR\_CONFIG\_NOTIFY，代码如下

```auto
	/* 6 读取服务CCCD初始化 */

    {

		DNA_BLE_ATTRIB_FLAG_VALUE_INCL | DNA_BLE_ATTRIB_FLAG_CCCD_APPL,

		{

			DNA_BLE_LO_WORD(DNA_BLE_GATT_UUID_CHAR_CLIENT_CONFIG),

			DNA_BLE_HI_WORD(DNA_BLE_GATT_UUID_CHAR_CLIENT_CONFIG),

			DNA_BLE_LO_WORD(DNA_BLE_GATT_CLIENT_CHAR_CONFIG_NOTIFY),

			DNA_BLE_HI_WORD(DNA_BLE_GATT_CLIENT_CHAR_CONFIG_NOTIFY)

		},

		2,

		NULL,

		(DNA_BLE_GATT_PERM_READ | DNA_BLE_GATT_PERM_WRITE)

	}

```

通过手机蓝牙调试助手，连接设备，获取服务器后，开启notify，无法接收到数据

---

<div class="post-metadata">

**Author:** ![wanglemao](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/wanglemao/32/1079_2.png) [@wanglemao](https://forum.amebaiot.com/u/wanglemao)\
**Post date:** [July 23, 2022, 6:26am UTC](https://forum.amebaiot.com/t/amebaz2-ble-cccd-default/1365/2 "2022-07-23T06:26:41Z")

</div>

手机APP，发送cccd为 1，即可接收数据，但是我在代码中已经初始化为DNA\_BLE\_GATT\_CLIENT\_CHAR\_CONFIG\_NOTIFY，为什么还需要再发送一次，我现在想实现手机不发送cccd 为1，即可收数据，请问该如何实现

---

<div class="post-metadata">

**Author:** ![wyy](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wyy](https://forum.amebaiot.com/u/wyy)\
**Post date:** [July 25, 2022, 2:19am UTC](https://forum.amebaiot.com/t/amebaz2-ble-cccd-default/1365/3 "2022-07-25T02:19:23Z")

</div>

按照 BLE 规格，CCCD 的默认值是 0x0000.  
只有在 Bond 了之后，CCCD 的状态才能保留，下次链接可以恢复 CCCD 上次断开前的状态，直接发送数据。

 ![Screenshot 2022-07-25 101602](https://us1.discourse-cdn.com/flex016/uploads/ameba/original/2X/8/8a600600bc63631bd02b79fc15b01a7f3cde83c3.png)  
 ![2](https://us1.discourse-cdn.com/flex016/uploads/ameba/original/2X/8/83a32247c27eb139119c3824e32f2a2fa083e255.png)

你也可以尝试不理 CCCD 值，直接发送数据 notification。但是有没有效果应该就要看 APP 了。

---

<div class="post-metadata">

**Author:** ![wanglemao](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/wanglemao/32/1079_2.png) [@wanglemao](https://forum.amebaiot.com/u/wanglemao)\
**Post date:** [July 27, 2022, 12:41am UTC](https://forum.amebaiot.com/t/amebaz2-ble-cccd-default/1365/4 "2022-07-27T00:41:59Z")

</div>

我已经尝试过直接发送数据，底层回调直接显示错误，cause：0x0c0a，APP也收不到，现在的做法手机连接成功后，主动发一次cccd为1，但是我们用的其他芯片都不存在这个问题，在代码中无法修改么

---

<div class="post-metadata">

**Author:** ![wyy](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wyy](https://forum.amebaiot.com/u/wyy)\
**Post date:** [July 27, 2022, 6:24am UTC](https://forum.amebaiot.com/t/amebaz2-ble-cccd-default/1365/5 "2022-07-27T06:24:15Z")

</div>

问了一下，麻烦你试试在开启 BLE 时调用这个 function：

```auto
typedef enum
{
    CONFIG_GATT_CCCD_CHECK, /**< Check cccd when server sends notification or indication. */
    CONFIG_GATT_CCCD_NOT_CHECK, /**< Not check cccd when server sends notification or indication. */
} T_GAP_CONFIG_GATT_CCCD_NOT_CHECK;

/**
 * @brief Configure whether to check cccd when server sends notification or indication.
 *
 * @param[in] cccd_not_check_flag Whether to check cccd: @ref T_GAP_CONFIG_GATT_CCCD_NOT_CHECK
 *
 * <b>Example usage</b>
 * \code{.c}
    void bt_stack_config_init(void)
    {
        gap_config_cccd_not_check(CONFIG_GATT_CCCD_NOT_CHECK);
    }
 * \endcode
 */
void gap_config_cccd_not_check(T_GAP_CONFIG_GATT_CCCD_NOT_CHECK cccd_not_check_flag);

```

> <https://github.com/ambiot/ambz2_sdk/blob/master/component/common/bluetooth/realtek/sdk/inc/bluetooth/gap/gap_config.h>

---

<div class="post-metadata">

**Author:** ![wanglemao](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/wanglemao/32/1079_2.png) [@wanglemao](https://forum.amebaiot.com/u/wanglemao)\
**Post date:** [August 29, 2022, 9:43am UTC](https://forum.amebaiot.com/t/amebaz2-ble-cccd-default/1365/6 "2022-08-29T09:43:19Z")

</div>

好的，谢谢，之前的版本直接让APP增加了一条设置cccd的命令，我后面在试试，看说明，应该能解决
