In order to use notifications in BLE peripheral mode, you will need to define the CCCD in the GATT database and send the notifications or indications according to the value the client sets it. I attached a zip file that has addition of code using a CCCD for notifications in the ble_proximity_reporter. Please look at the following for a description of changes made (in red).
** This was verified on a BCM943341WCD1 board with the iPhone LightBlue app.
1. First you will need to define the characteristic descriptor in wiced_bt_gatt_db.c, and also add properties to the characteristic that you want to receive notifications.
LEGATTDB_CHAR_PROP_READ | LEGATTDB_CHAR_PROP_NOTIFY | LEGATTDB_CHAR_PROP_INDICATE,
LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITE_REQ ),
2. In wiced_bt_gatt_db.h, add a handle for HDLC_TX_POWER_LEVEL_DESCRIPTOR,
// ***** Primary service 'TX Power'
3. In ble_proximity_reporter.c, add a global descriptor value and add a clause to function ble_proximity_gatt_write_request() to enable the client writing to the descriptor.
static int8_t proximity_tx_power_level_descriptor;
proximity_tx_power_level_descriptor = attribute_value;
WPRINT_APP_INFO( ("POWER_LEVEL_DESCRIPTOR written as 0x%x\n", attribute_value));
4. Once the descriptor is defined, we are going to use the function wiced_bt_gatt_send_notification() to send notifications every 2 seconds. We shall set the value to decrease from 20 to 1. The following code should be added in application_start() afterwiced_bt_stack_init() in ble_proximity_reporter.c.
void application_start( void )
/* Initialize WICED platform */
/* Initialize Bluetooth controller and host stack */
wiced_bt_stack_init( ble_proximity_management_callback, &wiced_bt_cfg_settings, wiced_bt_cfg_buf_pools );
for (uint8_t i = 20; i > 0; i-- )
// If notification is set
if ( proximity_tx_power_level_descriptor == 0x1 )
proximity_tx_power_level = i;
wiced_bt_gatt_send_notification (proximity_connection_handle, HDLC_TX_POWER_LEVEL_VALUE, sizeof(proximity_tx_power_level), &proximity_tx_power_level );
**For indications, use the function wiced_bt_gatt_send_indication() when the proximity_tx_power_level_descriptor == 0x2
5. For the first parameter in the function, proximity_connection_handle, this should be defined as a global variable and maintained inble_proximity_gatt_cback(). Whenever a new connection is established it should store the connection handle, and when connection is lost it should reset it to 0. ( Add red code in ble_proximity_reporter.c )
static uint16_t proximity_connection_handle = 0;
/* GATT event handler */
static wiced_bt_gatt_status_t ble_proximity_gatt_cback( wiced_bt_gatt_evt_t event, wiced_bt_gatt_event_data_t *p_event_data )
wiced_bt_gatt_status_t status = WICED_BT_GATT_SUCCESS;
switch ( event )
/* GATT connection status change */
bda = p_event_data->connection_status.bd_addr;
WPRINT_BT_APP_INFO( ("GATT connection to [%02X:%02X:%02X:%02X:%02X:%02X] %s.\n", bda, bda, bda, bda, bda, bda, (p_event_data->connection_status.connected ? "established" : "released")) );
if ( p_event_data->connection_status.connected )
/* Connection established. Get current TX power (required for setting TX power attribute in GATT database) */
wiced_bt_dev_read_tx_power( p_event_data->connection_status.bd_addr, p_event_data->connection_status.transport, (wiced_bt_dev_cmpl_cback_t *) ble_proximity_tx_power_callback );
/* Store information */
proximity_connection_handle = p_event_data->connection_status.conn_id;
/* Disable connectability. */
wiced_bt_start_advertisements( BTM_BLE_ADVERT_OFF, 0, NULL );
/* Connection released. Re-enable BLE connectability. */
wiced_bt_start_advertisements( BTM_BLE_ADVERT_UNDIRECTED_HIGH, 0, NULL );
/* test code for directed adv */
/* wiced_bt_start_advertisements (BTM_BLE_ADVERT_DIRECTED_HIGH, 0, p_event_data->connection_status.bd_addr); */
proximity_connection_handle = 0;
WPRINT_BT_APP_INFO( ("Waiting for proximity monitor to connect...\n") );
6. That's it! Now compile the code and download it to your WICED board. When you connect to "WICED Proximity" and select "Tx Power Level" from the LightBlue app of your iPhone (below) or the WICED Smart Explorer app in your Android device.
You should see the notifications arriving once you set "Listen to notifications". This app only counts down from 20 to 1 every 2 seconds after it resets, so if you don't see it counting down on your client try resetting the WICED board and connecting to it faster.
I hope this helped in getting you started with notifications!